位于服务器(和客户端referanced)调用jQuery脚本在IE不是法郎,而不是Chrome浏览器法郎、脚本、而不是、客户端

2023-09-10 21:48:04 作者:我们的故事像场烂电影

我有以下的情况,我有一个服务项目(ASMX)和Web项目(Java),我在ASP.NET开发服务器。

I have the following situation, i have a service project (ASMX) and a web project (ASPX) which i run localy on ASP.NET Development Server.

我有包含的功能是调用本地的asmx服务(因此一个福一个jQuery脚本,在jQuery脚本是在服务项目/脚本 - 做一些数据库插入和更新

I have a jQuery script that contain a handfull of functions which is calling the local asmx service (hence, the jQuery script is on the service project /Scripts - doing some database insertion and update.

在我的客户端页面我全球化志愿服务青年如下:

on my client page i referance the following:

 //Referance from client
 <script src="Scripts/jquery-1.3.1.js" type="text/javascript"></script>
 //Referance from service project
 <script src="http://localhost:4000/Scripts/Default.js" type="text/javascript"></script>
 //Referance from client
 <script src="Scripts/Caller.js" type="text/javascript"></script>

使用caller.js我应该能够调用Default.js功能,而跨域问题,该文件位于服务之外。这是工作,但只有在IE7和IE8。然而,在Chrome和Firefox 3也没有工作returing以下异常:

using the caller.js i should be able to call Default.js functions without cross-domain issues as the file is located beside the service. Which is working but only in IE7 and IE8. however in Chrome and FireFox 3 it didn't work returing the following exception:

[异常...组件返回故障code:0X80004005(NS_ERROR_FAILURE)nsIXMLHtt prequest.send]nsresult:0X80004005(NS_ERROR_FAILURE)的位置:JS框架::的的http://本地主机:4906 /脚本/ jQuery的-1.3.1.js ::匿名: :行3511数据显示:无]

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost:4906/Scripts/jquery-1.3.1.js :: anonymous :: line 3511" data: no]

和萤火我得到: 使用受限制的URI被拒绝code:1012

在一些谷歌上搜索这个turn'ed了一些相关的安全模型 - 跨域拦截,这是奇怪的,因为它适用于IE浏览器,我不认为我做任何跨域这里提及的默认以上。 JS(其中包含调用服务)所在的服务项目/服务器上。

After some googling this turn'ed out related to some Security Model - Cross-Domain blocking, which is weird as it works on IE and i don't think i am doing any Cross-Domain here as mentioned above the default.js (Which contains the calls to service) is located on the service project/server.

综述: 当referancing位于服务器上的一个脚本文件从客户端的任何调用,全球化志愿服务青年的文件生成此错误。

Summery: When referancing a script file that is located on the server any calls from a client that referance that file producing this error.

我的Ajax调用如下: 功能PingJSON(FNAME,LNAME,家庭){  // preparing参数和输出     VAR ID ='empty_response';     VAR PARAMS ={X:'+ FNAME +',Y:'+ L-NAME +Z:+家庭+'};

My Ajax Call is below: function PingJSON(fname,lname,family) { //Preparing Parameters and output var id='empty_response'; var params = "{x:'" + fname + "',y:'" + lname+ "',z:'"+ family + "'}";

//jQuert Ajax Call
$.ajax({
    type: "POST",
    url: "http://localhost:4000/MyService.asmx/PingService",
    data: params ,
    timeout: 10000,
    async:false,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) { //Success callback function
        id = msg;
    },
    error: function(xhr, ajaxOptions, thrownError) { //Fail callback function
        alert(xhr.status);
        alert(thrownError);
    }
});
return id;

};

推荐答案

看来你在呼唤从本地主机的脚本:4906和脚本位于本地主机:4000。端口还必须匹配,否则你会得到跨域错误。

It seems that you are calling the script from localhost:4906 and the script is located on localhost:4000. the ports must also match or you will get the cross-domain error.