/ / Questa pagina jQuery non funziona, perché? - jquery

Questa pagina jQuery non funziona, perché? - jquery

perché non funziona questo codice jQuery? Cosa c'è che non va?

Il comportamento previsto che avvisa del contenuto del file JSON richiesto ma non lo fa.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$.ajax({
type: "GET",
url: "http://api.xxxxxxxxx.com/0.1/cities/key=xxxx",
dataType: "jsonp",
crossDomain: true,
success: function(data){
$.each(data, function(i, el){
alert(el.city)
});
;}
});
</script>

<title>Example</title>
</head>
<body></body>
</html>

risposte:

2 per risposta № 1

La risorsa che stai caricando non è JSONP, è solo una stringa JSON, JSONP dovrebbe apparire così:

callback("jsonString");

Non tutti i json possono essere caricati come jsonp, deve essere configurato in modo specifico.

JSONP


0 per risposta № 2

la funzione deve avere il callback

callback({json:true});

e se non si ha il controllo sul server di destinazione, non è possibile effettuare richieste jsonp