tags:

views:

57

answers:

2

How to use xmlHttp Request.send()?......

My code in java script is as follows:

str_xml+="<xml_to_be_submitted><request_xml><client_id>"+document.frmCallEntryAdd.cboCLIENT.options[document.frmCallEntryAdd.cboCLIENT.selectedIndex].value+"</client_id></request_xml></xml_to_be_submitted>";
  var obj_http=new ActiveXObject("Microsoft.XMLHTTP");
  var str_url="ClientModuleFetch.aspx";
  var str_http_method="post";
  obj_http.open(str_http_method,str_url,false);
  obj_http.SetRequestHeader("Content-Type","application/x-www-form-urlencoded");
  obj_http.send(str_xml);
  var str_reply=obj_http.ResponseText;


  var xmlResponse = str_reply;

  var objXmlDOM=new ActiveXObject("Microsoft.XMLDOM");

Can any body tell what i had gone wrong?................

+1  A: 

For one, your method will only work in IE (I hope this isn't for a public website). A second error I can spot is that you've spelled SetRequestHeader with a capital S. It's supposed to be setRequestHeader.

Could you post exactly what error message (with the line number) you're getting, if any?

Matti Virkkunen
A: 

Your posted data is not application/x-www-form-urlencoded, which looks like this a=b&c=f.

Your posted data is either application/xml or text/xml which is generally not used with XMLHttpRequest unless you are manually constructing SOAP packets.

It is my guess that you are calling a script enabled service endpoint that can accept url encoded parameters so perhaps the manually constructed XML is not the appropriate data to post.

If not, you will need to explore the special corner of hades that is reserved for those who insist on calling SOAP from JavaScript. I do not envy you. ;-)

The return, on the other hand, possibly is XML that you will need to parse. I would suggest using a more cross browser compatible method for both XMLHttpRequest construction as well as XML parsing as your code seems to be IE centric.

Also, as noted elsewhere, you have a typo r.e. SetRequestHeaders should be setRequestHeaders.

Sky Sanders
Can you suggest the correct way to send (code) my str_xml to get an xml response.....
Harun
@harun - before I could do that I would need to know what type of service you are calling. e.g. is it an asp.net webservice (with optional scriptservice attribute), ajax enabled wcf service, some arbitrary soap service that you have no control over etc...
Sky Sanders
Hi, Actually i am using the javaScript along with asp.net (it is an old application; might be using asp.net web service). I just want to send an id through a POST method to another page where i am retrieving a set of records from DB (to avoid page refreshing). I need to get those records as response xml. I am familiar with the use of page method to do this fetching within the same page without refreshing the page. But i just want to know the other way.
Harun
@harun - then you probably don't need to send xml. It would help if you post the code of ClientModuleFetch.aspx, otherwise anything will just be a guess.
Sky Sanders
Hi, my ClientModuleFetch.aspx looks like this:obj_xml_dom = New MSXML.DOMDocument;str_xml = Request.Form.Item.GetValue(0);rst_module = New ADODB.Recordset;str_reply= from DB using rst_module;str_reply = str_reply Response.Write((str_reply));
Harun