By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

Ajax call not working

P: n/a
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 !

May 4 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Zeba wrote:
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);

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 4 '07 #2

P: n/a
Sorry for the late response; anyway , thanks!

May 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.