Javascript – Call jQuery script located at server (and referanced by client) works on IE not FF and not Chrome

ajaxjavascriptjquery

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.

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>

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:

[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]

and on FireBug i get:
Access to restricted URI denied" code: "1012

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.

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

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;

};

Best Answer

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.

Related Topic