• 0

JavaScript + C# WebService error


Question

I am getting an error with the following code, and my ignorance of this subject is an issue.  Any ideas?

var xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.open("POST", "http://feelzmecom.webhost4life.com/FeelzMeSRV.asmx/HelloFeelz", false);       
xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttpReq.send();                     //At this line I get err.message = "undefined"
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

At a guess, your browser is probably enforcing the "Same Origin Policy".

 

edit: And yeah, the web site is also broken, but if was working you should be getting an error code, not an exception.

  • Like 1
Link to comment
Share on other sites

  • 0

 

I am getting an error with the following code, and my ignorance of this subject is an issue.  Any ideas?

var xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.open("POST", "http://feelzmecom.webhost4life.com/FeelzMeSRV.asmx/HelloFeelz", false);       
xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttpReq.send();                     //At this line I get err.message = "undefined"

 

"HelloFeez" does exist, see here:  http://feelzmecom.webhost4life.com/FeelzMeSRV.asmx

 

I'm tired and going to sleep, but I will check it with my C# Desktop app, but even the other two services are giving me the same error

Link to comment
Share on other sites

  • 0

UPDATE:

 

The following code works, but the response is showing: Error 404.0 The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

 

I ran a test app from C# and the functions, all three of them work within that, so I know the functions work.  wth am I doing wrong?

 

 

JavaScript code.

xmlHttpReq.open("POST", "http://feelzmecom.webhost4life.com/FeelzMeSRV.asmx/HelloFeelz", false);				
xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttpReq.send();                         
alert(xmlHttpReq.responseText);

C# Code:

        [WebMethod(CacheDuration = 2, Description = "Just a Test.")]
        public string HelloFeelz()
        {
            return "The time is " + DateTime.Now.ToShortTimeString();
        }

Link to comment
Share on other sites

  • 0

Well, it's been a fun few days.  I got it working, but of course I now have another issue.

 

Working code

function GetFeelz(){ 
	try {
		var sURL = 'Test1';
		var xmlHttpReq = new XMLHttpRequest();
				
		xmlHttpReq.open("POST", "http://feelzmecom.webhost4life.com/FeelzMeSRV.asmx", false);
		xmlHttpReq.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
		xmlHttpReq.send("<?xml version='1.0' encoding='utf-8'?><soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'><soap12:Body><GetFeelz xmlns='http://feelzmecom.webhost4life.com/'><sInput>" + sURL + "</sInput></GetFeelz></soap12:Body></soap12:Envelope>");

		var xmlDoc = xmlHttpReq.responseXML;
		var htmlCollection = xmlDoc.getElementsByTagName("GetFeelzResult");
		sURL = htmlCollection[0].childNodes[0].nodeValue;
		alert("Return Value: " + sURL);
	}
	catch (Err) {
		alert("ERROR!: " + Err.Message + ' at ' + Err.lineNumber);
	}
}

This works fine if I am calling from the same domain... which introduced me to "Access-Control-Allow-Origin"  My Web Service's web.config file now has the following, but I still get an error of "undefined" on this line;  xmlHttpReq.send

 

Any thoughts?

    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*"/>
          <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
        </customHeaders>
      </httpProtocol>
Link to comment
Share on other sites

This topic is now closed to further replies.