2013-01-15 31 views
0

我正在开发从JSON响应中加载数据的示例jQuery插件。

我不是为什么,但它没有调用成功的方法。它会去.error()方法。谁可以帮我这个事?

http://www.technicalkeeda.com/demos/load_scroll_content返回适当的JSON响应。

$.getJSON('http://www.technicalkeeda.com/demos/load_scroll_content?callback=?'); 

jQuery的AJAX功能将取代最后:从服务

[[{"EMPLOYEE_ID":"1","EMPLOYEE_NAME":"Yashwant Chavan"},{"EMPLOYEE_ID":"2","EMPLOYEE_NAME":"Mahesh Diwan"},{"EMPLOYEE_ID":"3","EMPLOYEE_NAME":"Rajesh Limaye"},{"EMPLOYEE_ID":"4","EMPLOYEE_NAME":"Pankaj Patil"}]] 
+1

这不是一个JSONP服务。 – SLaks

+1

什么是错误? – Archer

+1

@Slaks,所以我需要在服务器端的变化,正确工作,所以你有什么想法我需要改变,? – Vicky

回答

2

您需要添加JSONP回调参数,这样

<script> 

    $(document).ready(function() { 

    var jqxhr = $.getJSON('http://www.technicalkeeda.com/demos/load_scroll_content', function(data) {   
     alert("success"); 
    },"json").success(function() { alert("second success"); }) 
    .error(function(xhr, testStatus, error) { 

     alert('Error' + xhr.status); 
     alert('Error' +xhr.response); 
     alert('Error' +xhr.responseText); 

    }) 
    .complete(function() { alert("complete"); }); 
    jqxhr.complete(function(){ alert("second complete"); }); 

}); 
</script> 

回应?像 'jQuery12345' 和响应应该使用回调参数值这样一个随机字符串:

jQuery12345([ 
    {"EMPLOYEE_ID":"1","EMPLOYEE_NAME":"Yashwant Chavan"}, 
    {"EMPLOYEE_ID":"2","EMPLOYEE_NAME":"Mahesh Diwan"} 
]) 

你可以阅读更多有关JSON这里:

相关问题