Ajax call not working

Z

Zeba

Hi guys!

I'm new to JS / Ajax; I've been trying to do an Ajax call to my
Webservice ( I'm using C# for code-behind). I'm not using any of the
libraries available. I am sending my CustID to the webservice and the
webservice returns a Dataset that contains various customer details
taken from database. I have tested that the Webservice itself works.
But my ajax call is not working.

My ajax call is something like :

this.URL = "http://localhost/RegistrationAjax/Retrieve.asmx";
this.webMethod = "getCustomerDetails";
var url = this.URL +"/"+ this.webMethod;
this.request.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
this.request.open('POST', url, true);
this.request.onreadystatechange = this.onComplete;
this.request.send("custID="+cust_id);

I also tried it using GET, as :
var url = this.URL +"?op="+ this.webMethod;
this.request.open('GET', url, true); //Also tried
this.request.open('GET', url, false);
this.request.onreadystatechange = this.onComplete;
this.request.send("custID="+cust_id);
(also tried appending the cust_id to the url for GET )

But what I get back ( i.e. what I see in the Response tab for the GET
entry in the console of Firebug) is the entire html of the webservice
itself. Why am i not getting the Data ??!

In the case of POST, I get an exception that says:

uncaught exception: [Exception... "Component returned failure code:
0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.setRequestHeader]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://localhost/RegistrationAjax/JS/RemoteControl.js :: anonymous ::
line 56" data: no]


Please help me out !!!! How do I actually get to my Webservice from my
Javascript ??!

Thanks !
 
L

-Lost

Zeba said:
Hi guys!

I'm new to JS / Ajax; I've been trying to do an Ajax call to my
Webservice ( I'm using C# for code-behind). I'm not using any of the
libraries available. I am sending my CustID to the webservice and the
webservice returns a Dataset that contains various customer details
taken from database. I have tested that the Webservice itself works.
But my ajax call is not working.

My ajax call is something like :

<snipped class>

I would try setting up the request in a much simpler fashion before
adding it to a function class.
But what I get back ( i.e. what I see in the Response tab for the GET
entry in the console of Firebug) is the entire html of the webservice
itself. Why am i not getting the Data ??!

Make sure you check the contents of your responseText, or responseXML
just to be sure.

It sounds as though your "webservice" is not outputting the content you
seek.
In the case of POST, I get an exception that says:

uncaught exception: [Exception... "Component returned failure code:
0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.setRequestHeader]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://localhost/RegistrationAjax/JS/RemoteControl.js :: anonymous ::
line 56" data: no]

This error relates to you calling the setRequestHeader before the call
to open.
Please help me out !!!! How do I actually get to my Webservice from my
Javascript ??!

For simplicity's sake (assuming non-IE):

var xhr = new XMLHttpRequest;
xhr.open('POST', 'yourWebService.aspx', true);
// setRequestHeader if you like
xhr.onload = function()
{
alert(xhr.responseText);
}
xhr.send(null);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top