2012-04-25 17 views
8

Sto usando il seguente codice per prelevare dati da JSON.

$(document).ready(function() 
{ 
    $.getJSON("http://www.xyz.com/data.php?id=113&out=json", function(data) { 

     $.each(data.issue.page, function(i,item) { 
      imagesJSON[i] = item["@attributes"]; 
     }); 

     alert(imagesJSON.length); 
    }); 
}); 

Funziona in Mozilla, Chrome e altri browser ma non in IE. (Non in qualsiasi versione).

+4

se potessimo vedere il risultato JSON ... – gdoron

+2

quale versione di jquery e questo link è nel dominio in cui si trova lo script? –

+3

Errori nella console JS? ... – binarious

risposta

14

$.getJSON ha una tendenza a cache results in IE. Utilizzare invece $.ajax.

La chiamata relativa dovrebbe essere qualcosa di simile nel tuo caso:

// Not really sure if you've forgot to var 
var imagesJSON = []; 

$.ajax({ 
    url: "www.example.com/data.php?id=113&out=json", 
    cache: false, 
    dataType: "json", 
    success: function(data) { 
    $.each(data.issue.page, function(i,item) { 
     imagesJSON[i] = item["@attributes"]; 
    }); 

    alert(imagesJSON.length); 
    }, 
    error: function (request, status, error) { alert(status + ", " + error); } 
}); 

Accertarsi che siano presenti cache: false.


UPDATE:

Sembra essere un problema di configurazione al host con la richiesta URL che l'OP in realtà usa. Andando all'URL direttamente con il browser Web di IE si ottiene un annullamento dall'host. Non puoi fare molto più che segnalare il problema all'host, ad esempio un'email al webmaster dell'host.

+0

Io uso questo. C'è qualche problema '$ .ajax ({ \t \t url: "http://www.xyz.com/data.php?id=113&out=json", \t \t della cache: false, \t \t dataType:" json", \t \t successo: la funzione (i dati) { \t \t \t $ .each (data.issue.page, la funzione (I, punto) { imagesJSON [i] = item [ "@ attributi"]; \t Avviso \t \t (imagesJSON.lunghezza); }); \t \t errore: funzione (richiesta, stato, errore) { avviso (stato + "," + errore); \t \t } ' –

+0

@ketan: sei sicuro di averlo inserito correttamente? il valore per l'errore della chiave (che è quella funzione che hai lì) dovrebbe essere all'interno della serie di parametri per la funzione '$ .ajax'. – Spoike

+4

Le cose di cui sopra mi danno errore in IE come ** Errore, Nessun trasporto ** –

2

Ho avuto lo stesso errore su una pagina, e ho aggiunto queste righe:

<!--[if lte IE 9]> 
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.0/jquery.xdomainrequest.min.js'></script> 
<![endif]--> 

e funziona finalmente per me;) non più di errore per IE9

Questo post mi aiuta jQuery Call to WebService returns "No Transport" error