2011-12-23 79 views
0

我有一個JSON調用是跨站點。如果我使用IE8由於Firefox的工作沒有問題而受到較低的限制。如果我添加&回調=?到它剛剛死亡的功能。我甚至無法看到在Firebug中進行的AJAX調用。一旦將其添加到URL中,IE8和Firefox都會靜默地死去。添加&callback =?到jQuery功能失敗

$(document).ready(function(){ 
var url = 'http://www.example.com/PeopleSearch/?search=tim&callback=?'; 

$.ajax({ 
    url: url, 
    dataType: 'json', 
    data: {}, 
    success: function(data) { 
    alert(data) 
    }, 
    error: function(XMLHttpRequest, textStatus, errorThrown) { 
    alert(textStatus); 
    alert(errorThrown); 
    } 
}); 
}); 
+0

當您添加的回調會發生什麼=%3F – 2011-12-23 03:31:12

+0

下降具體的數據類型和數據屬性,並嘗試 – Joe 2011-12-23 03:32:29

+0

@PenchoIlchev - 一點也沒有」不要把它當作JSONP。所以它回落到IE8而不是FF。 – going 2011-12-23 03:35:08

回答

0

阿賈克斯與jQuery的更安全的方式:)

$(document).ready(function(){ 
var url = 'http://www.example.com/PeopleSearch'; 

$.ajax({ 
    url: url, 
    type : "POST", 
    dataType: 'json', 
    data: {"search":"tim","callback":""}, 
    success: function(data) { 
    alert(data); //It will be something like [Object object,since it is encoded as json from the server side] 
    }, 
    error: function(data) { 
      alert(data); 
    } 
}); 
}); 

/******************SERVER SIDE****************/ 
//do stuff.... 
echo json_encode($result);exit;