-
June 16th, 2010, 05:16 PM
#1
Need help with SOAP with JavaScript
I have a current function in javascript that is trying to use soap to get some values from a web service. However, I keep getting errors such as "Unterminated String Constant" and "Object Expected"
here is my function:
Code:
<script type="text/javascript">
function test1(){
var oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
oXmlHttp.open("POST","http://www.webservicex.net/WeatherForecast.asmx?wsdl",false);
oXmlHttp.setRequestHeader("Content-Type", "text/xml");
oXmlHttp.setRequestHeader("SOAPAction", "http://www.webservicex.net/GetWeatherByZipCode");
oXmlHttp.send(" \
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body> \
<GetWeatherByZipCode xmlns='http://www.webservicex.net'> \
<ZipCode>60609</ZipCode> \
</GetWeatherByZipCode> \
</soap:Body> \
</soap:Envelope> \
");
alert(oXmlHttp.responseText);
}
</script>
Here is the WSDL url:
http://www.webservicex.net/WCF/Servi...ls.aspx?SID=44
Last edited by PeejAvery; June 16th, 2010 at 07:48 PM.
Reason: Added code tags
-
June 16th, 2010, 08:50 PM
#2
Re: Need help with SOAP with JavaScript
Originally Posted by bagznboardz
However, I keep getting errors such as "Unterminated String Constant" and "Object Expected"
That's what you get when you spread a string through 11 line returns. Make sure the string you are sending is valid.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 17th, 2010, 09:40 AM
#3
Re: Need help with SOAP with JavaScript
Even when I take the line returns out and combine the string into 2 lines or one variable I still get the same error.
-
June 17th, 2010, 12:27 PM
#4
Re: Need help with SOAP with JavaScript
I don't get any error when I put it all on one line.
Code:
oXmlHttp.send("<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetWeatherByZipCode xmlns='http://www.webservicex.net'><ZipCode>60609</ZipCode></GetWeatherByZipCode></soap:Body></soap:Envelope>");
Also, why are you not checking the onreadystatechance before alerting the return?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 17th, 2010, 01:11 PM
#5
Re: Need help with SOAP with JavaScript
So I was able to fix the code for the unterminated string constant error in a regular test html page. However, the html page is now getting a permission denied error on the oXmlHttp.open method.
Also my production code is still getting a unterminated string constant error.(The production app uses my embedded js as part of its XSL code). For some reason the same code I used in the html page still gives me a untermed string constant error in the XSL page. Im thinking that the app is changing the code for some reason. I validated it as well before hand. I have tried using the " for the quotes, but then it doesnt validate....
Here is my updated code without the onreadystatechange addition you mentioned.
Code:
<script type="text/javascript">
function test1(){
var oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
alert('beforeOpen');
netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);
oXmlHttp.open("POST","http://www.webservicex.net/WeatherForecast.asmx?wsdl",true);
alert('beforesetRequestHeader1');
oXmlHttp.setRequestHeader("Content-Type", "text/xml");
alert('beforesetRequestHeader2');
oXmlHttp.setRequestHeader("SOAPAction", "http://www.webservicex.net/GetWeatherByZipCode");
alert('beforeSEND');
oXmlHttp.send("<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
+ "xmlns:xsd='http://www.w3.org/2001/XMLSchema' "
+ "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> "
+ "<soap:Body> "
+ "<GetWeatherByZipCode xmlns='http://www.webservicex.net'> "
+ "<ZipCode>60609</ZipCode>"
+ "</GetWeatherByZipCode> "
+ "</soap:Body>"
+ "</soap:Envelope> "
+ " \"");
alert(oXmlHttp.responseText);
}
</script>
Thanks for your help on these errors.
Last edited by PeejAvery; June 17th, 2010 at 01:28 PM.
Reason: Added code tags.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|