我的以前版本的这个ajax代码在测试过程中完美地运行google-chrome --disable-web-security
用选项填充一个select元素然而现在我重写了一些代码来使用jsonp它不起作用我无法想象如何解决它。
jQuery.ajax({
url: xmlrpcproxy + '?callback=jsonpcallbackfunc', // <--- returns valid json if accessed in the browser
type: "GET",
cache: false,
contentType: "jsonp", // Pay attention to the dataType/contentType
dataType: 'jsonp', // Pay attention to the dataType/contentType
jsonpCallback: 'jsonpcallbackfunc',
});
function jsonpcallbackfunc (data) {
var firstoption = '<option value="select" selected>Please Select</option>';
jQuery("select#ItemIDSelect").html(firstoption);
var i;
var erplist = JSON.parse(data);
alert(data);
for (i = 0; i < erplist.length; ++i) {
jQuery("select#ItemIDSelect").append('<option value="' + erplist[i] + '">' + erplist[i] + '</option>');
}
}
被叫服务器页面返回
jsonpcallbackfunc(["admin2", "Administrator", "Afdeling XCV", "Agrolait", "Angel Cook", "Arthur Gomez", "ASUSTeK", "Axelor", "Axelor", "Ayaan Agarwal", "Bank Wealthy and sons", "Benjamin Flores", "Best Designers", "Brian Williams", "Camptocamp", "Chamber Works", "Chao Wang", "Charlie Bernard", "China Export", "Clement Marsot", "Coin gourmand", "Daniel Jackson", "David Simpson", "Delisle Albert", "Delta PC", "Demo User", "Donald Thompson", "Edward Foster", "Elec Import", "Epic Technologies", "Fabian Semal", "George Wilson", "Global Solutions", "Jacob Taylor", "Jacque Marseille", "James Miller", "Jan Bart", "Jessica Dupont", "John M. Brown", "Joseph Walters", "Julia Rivero", "Kevin Clarke", "Laith Jubair", "Laura Castro", "Lucas Jones", "Luc Maurer", "Luminous Technologies", "Mark Davis", "Marketing Business", "Mediapole", "Michel Fletcher", "Millennium Industries", "Morgan Rose", "Natuurpunt vzw", "Nebula Business", "Nhomar Hernandez", "Paul Williams", "Peter Mitchell", "Phillipp Miller", "Pizza Inn", "Richard Ellis", "Robert Anderson", "Robin Smith", "Roger Scott", "Seagate", "Sergio P\u00e9rez", "Spark Systems", "Steven Hamilton", "Tang Tsui", "Template User", "The Jackson Group", "The Poste", "Think Big Systems", "Thomas Passot", "Tom Pintens", "Vauxoo", "Vicking Direct", "William Thomas", "Your Company", "Your Company, Birmingham shop", "Your Company, Chicago shop", "Zhi Ch'ang"])
UPDATE:该函数现在触发并将静态选项添加到select元素。但是var erplist = JSON.parse(data);
得到意外的令牌a(来自admin2)我需要为JSON.parse(数据)更改什么才能失败,我是否会以某种方式更改数据?
感谢您阅读!