J'aime travailler avec JSON et jquery. Lorsque je test hors ligne de script sur localhost il fonctionne très bien, mais quand je change ce fichier JSON à un serveur, il doens't travailler al tousJSON avec php et Jquery
jQuery(function($) {
$.ajax
({
type: "GET",
url: "test.php",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: companySearchSuccess,
error: onError
});
function companySearchSuccess(json)
{
alert("stap1");
var select = $('#city-list');
$.each(json, function(k, v) {
var option = $('<option />');
option.attr('value', v)
.html(v)
.appendTo(select);
});
}
function onError(m){
alert("Fout is: "+m);
}
});
Cela fonctionne bien,
mais celui-ci ne:
jQuery(function($) {
$.ajax
({
type: "GET",
url: "http://www.example.com/test.php",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: companySearchSuccess,
error: onError
});
function companySearchSuccess(json)
{
alert("stap1");
var select = $('#city-list');
$.each(json, function(k, v) {
var option = $('<option />');
option.attr('value', v)
.html(v)
.appendTo(select);
});
}
function onError(m){
alert("Fout is: "+m);
}
});
L'erreur est: objet XMLHttpRequest>
S'il vous plaît aidez-moi