$就调用工作正常在IE8,不会在Firefox和Chrome浏览器工作 [英] $.ajax call working fine in IE8 and Doesn't work in firefox and chrome browsers

查看:200
本文介绍了$就调用工作正常在IE8,不会在Firefox和Chrome浏览器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code

$.ajax(
{
    type: "GET", 
    url: 'http://devserver:7995/stdpart/services/GetAllPartsWithFilter',
    dataType: 'json',
    data: jsonPartsData,
    success: fnGetPartsData, 
    error: PartsLoadError  
});

这是code在IE8中工作正常,但没有得到在Firefox和Chrome浏览器。当我检查XHR对象,它说的状态code code是0。我已经检查了所有其他问题,他们都不帮我找出这个问题。

This is code working fine in IE8, But getting failed in Firefox and Chrome browsers. When i, inspect the XHR object, it's saying the status code code is 0. I have checked all other questions, none of them are helped me to identify the issue.

让我知道,如果我做任何事情错在这个code。如果$就具有一定的兼容性问题,则请提出一些等同于它。

Let me know, if i am doing any thing wrong in this code. If $.ajax has some compatibility issues, then please suggest something equivalent to it.

更新: 我们找到了一个解决方案,在 http://www.xml.com /pub/a/2005/12/21/json-dynamic-script-tag.html

Update: We found one solution at http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html

据使用的动态脚本的概念。我们已经在我们的应用程序做同样的事情,那么每一件事情似乎是现在的工作。然而,要全面分析。

It is using the concept of Dynamic Scripting. We have done the same thing in our application, then every thing seems to be working now. Yet to analyze fully.

推荐答案

这是因为同根同源政策。你不能使用AJAX调用外部网站。如果你真的想用,你必须使用 JSONP 。或者你可以使用服务器端的代理这一点。意味着,调用外部网站的服务器端,并尽到了AJAX Web服务调用。

this is because of the Same origin policy. you cannot use ajax to call external sites. if you really want to use, you have to use JSONP. Or you can use serverside proxy for this. means, call external site in the server side and do ajax call to the that webservice.

更新:

UPDATE:

在您的网站上创建webserveice和投入的WebMethod以下code

create webserveice in your site and in the webmethod put following code

string proxyURL = "http://devserver:7995/stdpart/services/GetAllPartsWithFilter";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(proxyURL);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response.StatusCode.ToString().ToLower() == "ok")
{
    Stream content = response.GetResponseStream();
    StreamReader contentReader = new StreamReader(content);         
    return contentReader.ReadToEnd();
}
return string.Empty;

然后使用你的code访问本地服务。

then access local service using your code.

更多信息,请参见本链接

这篇关于$就调用工作正常在IE8,不会在Firefox和Chrome浏览器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆