我尝试在本地网络中运行以下jquery代码。
I try to run the following jquery code in local Network.
$.ajax({ type: "GET", url: "SomeSite/MyUrl/", cache: false, data: { ... }, dataType: "json", error: function (xhr, status, error) { ... }, success: function (json) { ... });一切正常,直到SomeSite是localhost。我的意思是从下载页面的同一台服务器。
Everything works fine until "SomeSite" is localhost. I mean the same server from what the page was downloaded.
但是当SomeSite是另一个(不是localhost)网络站点时,它看起来像请求挂起。不是错误,也不是成功回调函数被调用。如何使这段代码工作?
But when 'SomeSite' is another (not localhost) network site it looks like request hangs. Not "error", nor "success" callback functions are called. How can I make this code work?
提前谢谢!
推荐答案我有同样的问题。尝试从服务器获取json,我无法访问(=>没有JSONP)。
I had the same issue. Trying to get json from a server to wich I dind't had access (=> no JSONP).
我发现 benalman/projects/php-simple-proxy/ 将php代理添加到您的服务器,并对此文件进行ajax调用。 要传递到远程URL资源的任何GET参数必须在此参数中进行编码。
I found benalman/projects/php-simple-proxy/ Add the php proxy to your server and do the ajax call to this file. "Any GET parameters to be passed through to the remote URL resource must be urlencoded in this parameter."
$.ajax({ type: 'GET', url:'proxy.php?url=anyDomain?someid=thispage', dataType: "json", success: function(data){ // success_fn(data); }, error: function(jqXHR, textStatus, errorThrown) { // error_fn(jqXHR, textStatus, errorThrown); } });其中proxy.php(Ben Alman的文件)托管在您的域
where proxy.php (the file from Ben Alman) is hosted in your domain
(我发现这是第二好的): james.padolsey/javascript/cross-domain-requests-with-jquery/
更多推荐
JSON:如何进行跨域JSON调用
发布评论