XmlHttpRequest Response
I got some kind of incomprehensible problem and I need help I wrote some code to initialize xmlHttpRequest to send request AND get some answers, here is my code:
function initRequest(url)
{
if(window.XMLHttpRequest){
req=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
isIE=true;
req=new ActiveXObject("Microsoft.XMLHTTP");
}
}
function validateUser()
{
var sPath = window.location.pathname;
var sAddress = sPath.substring(0,sPath.lastIndexOf('/') + 1);
var url=sAddress+"WebService2.asmx?op=HelloWorld";
initRequest(url);
req.onreadystatechange=processRequest;
req.open("GET",url,true);
req.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
req.send(null);
}
function processRequest()
{
if(req.readyState==4){
if(req.status==200)
{
var message="invalid";
alert(req.responseText);
//message=req.responseXML.getElementsByTagName("valid")[0].childNodes[0].nodeValue;
//SetMessage(message);
}
else
{
alert(req.statusText);
}
}
}
My problem: I don't know where / how to get the correct XML response from Url Im Specifying, I was working with Respos object in HelloWorld method of my WebService, but the result was some kind of page DOM architecture to call the method ...
Every single key will be appreciated
There are two possible answers to this question.
- A lengthy and detailed discussion of the interpretation of status codes and analysis results.
- It is suggested that you look at using an installed library to get rid of it because of this.
I'll take the second approach and recommend that you research jquery as it does all the donkey work for you - and provides a ton of other benefits. Then you can develop your application freely instead of spending hours on problems that others have already solved.
PS I admit the existence of other javascript libraries, sucah as 'prototype', but found jquery to suit all my needs, and is also included in the ASP.NET MVC framework, making it hassle-free.
a source to share
If you don't want the DOM, but rather the XML response as a string, use responseText instead of responseXML.
Also, consider using prototype or jquery instead of writing it by hand.
If the answer is different from what you expected, you may be mistakenly assuming that the api. I would recommend reading the documentation for it or tcpdumping data exchange.
You have not specified which server you are connecting to, so we cannot help you on its api.
a source to share