开发者

Using XMLHttpRequest.send() in JavaScript

How do I use XMLHttpRequest.send()?

My code in JavaScript 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 me what I am doing wrong?


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜