JSONP是为建设混搭非常强大的技术,但不幸的是,它不能治愈所有所有的跨域通信的需求。它有一些缺点之前犯下的发展资源,必须认真考虑采取。首先,有没有JSONP形式调用的错误处理。如果动态脚本插入的工作,你叫;如果不是,什么也没有发生。它只是静静地失败。例如,你是不是能够赶上从服务器404错误。你也可以取消或重新启动的要求。你可以,但是,超时后,等待一个合理的时间。 (未来jQuery的版本可能有一个JSONP请求中止的功能。) However there's a jsonp plug-in available on GoogleCode that provides support for error handling. To get started, just make the following changes to your code. You can either download it, or just add a script reference to the plug-in.
<script type="text/javascript" src="http://jquery-jsonp.googlecode.com/files/jquery.jsonp-1.0.4.min.js"> </script>
$.jsonp({ url:'http://192.168.0.102:8080/web/view/pricePad/test', dataType:"jsonp", callbackParameter:"jsonpcallback2", async:false, timeout:5000, success:function(data){ alert("成功"); }, error:function(XMLHttpRequest, textStatus, errorThrown) { //alert("wrong!!"); alert("ERREUR: " + textStatus); alert("ERREUR: " + errorThrown); }, complete: function(XMLHttpRequest, textStatus) { alert("over") this; // 调用本次AJAX请求时传递的options参数 } });