views:

324

answers:

2

Hi,

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;

};

A: 

Just a thought, but perhaps referencing with the fully qualified path "http://..." is what's causing FF3 and Chrome to think you're attempting cross domain? Switch to using relative paths, and see what happens.

Stefan Kendall
Thanks iftrue for your suggestion, but how can i change http://localhost:4000 to a relative format? Thanks again.
Adel
Ach, I guess you can't, but is there a reason the service has to serve the files? I would think tossing Default.js in the local Scripts directory may cause this to work.
Stefan Kendall
I had to have the service serving the default.js to overcome the cross domain issue.
Adel
i think the problem maybe because i have ref two jquery lib one of the server and one on the client but don't know how to make sure the script at the server use it's own and etc for the client?
Adel
Okay, if Russ is right? how can i get this to work in IE?
Adel
+3  A: 

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.

Russ Bradberry
sorry for the revision Russ, accidentally hit the wrong button.but ya, your answer is what i was going to say. its cross domain.
Mike_G