javascript - ajax jsonp我写的方法怎么调用不了? 为什么用$.getJSON方法能生成数据?
ringa_lee
ringa_lee 2017-04-11 13:13:43
0
2
375

http://jsbin.com/curofericu/e...

//   $.getJSON("http://www.runoob.com/try/ajax/jsonp.php?jsoncallback=?", function(data) {
    
//     var html = '<ul>';
//     for(var i = 0; i < data.length; i++)
//     {
//         html += '<li>' + data[i] + '</li>';
//     }
//     html += '</ul>';
    
//     $('#pCustomers').html(html); 
// });

我把上面的方法转成ajax的方法

$.ajax({
  method: "post", //get/post试过了 
  async: false,
  url: "http://www.runoob.com/try/ajax/jsonp.php",
  dataType: "jsonp",
  jsonp: "jsoncallback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)
  jsonpCallback:"?",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名,也可以写"?",jQuery会自动为你处理数据
  success: function(data){
  var html = '<ul>';
  for(var i = 0; i < data.length; i++)
  {
  html += '<li>' + data[i] + '</li>';
}
       html += '</ul>';

       $('#pCustomers').html(html); 
},
  error: function(){
    alert('fail');
  }
});

为什么会进入error啊
好奇怪。
如何正确使用ajax jsonp里面的方法 。

案例http://www.runoob.com/json/js...

ringa_lee
ringa_lee

ringa_lee

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!