Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript SOAP xmlhttprequest issue mobile
    text
    copied!<p>All right, so previously I asked... SOAP Prototype AJAX SOAPAction Header Question (can't hyperlink it unfortunately, not enough rep for "2" links... see below)</p> <p>Which never worked out. I think it has something to do with Prototype, it will return a 0 as onSuccess. I can't figure out the Content-type utf-8 formatting. Now if I go back to straight javascript and use xmlhttprequest</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; </code></pre> <p> </p> <pre><code> function getUVIndex() { // In Firefox, we must ask the user to grant the privileges we need to run. // We need special privileges because we're talking to a web server other // than the one that served the document that contains this script. UniversalXPConnect // allows us to make an XMLHttpRequest to the server, and // UniversalBrowserRead allows us to look at its response. // In IE, the user must instead enable "Access data sources across domains" // in the Tools-&gt;Internet Options-&gt;Security dialog. if (typeof netscape != "undefined") { netscape.security.PrivilegeManager. enablePrivilege("UniversalXPConnect UniversalBrowserRead"); } // Create an XMLHttpRequest to issue the SOAP request. This is a utility // function defined in the last chapter. var request = new XMLHttpRequest(); // We're going to be POSTing to this URL and want a synchronous response request.open("POST", "http://iaspub.epa.gov/uvindexalert/services/UVIndexAlertPort?wsdl", false); request.onreadystatechange=function() { if (request.readyState==4) { var index = request.responseXML.getElementByTagName('index')[0].firstChild.data; alert(request.responseText); } } // Set some headers: the body of this POST request is XML request.setRequestHeader("Content-Type", "text/xml"); // This header is a required part of the SOAP protocol request.setRequestHeader("SOAPAction", '""'); // Now send an XML-formatted SOAP request to the server request.send( '&lt;?xml version="1.0" encoding="utf-8"?&gt;' + '&lt;soap:Envelope' + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' + ' xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"' + ' xmlns:tns="urn:uvindexalert" xmlns:types="urn:uvindexalert/encodedTypes"' + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;' + ' &lt;soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;' + ' &lt;tns:getUVIndexAlertByZipCode&gt;' + ' &lt;in0 xsi:type="xsd:string"&gt;12306&lt;/in0&gt;' + ' &lt;/tns:getUVIndexAlertByZipCode&gt;' + ' &lt;/soap:Body&gt;' + '&lt;/soap:Envelope&gt;' ); // If we got an HTTP error, throw an exception if (request.status != 200) throw request.statusText; //return request.responseXML.childNodes[0].childNodes[1].childNodes[3].childNodes[5].textContent; } getUVIndex(); &lt;/script&gt; </code></pre> <p></p> <p></p> <p> </p> <p>This never calls the onreadystatechange. If you uncomment the return request.responseXML.childNodes[0].childNodes[1].childNodes[3].childNodes[5].textContent;</p> <p>It will retrieve the value needed and if you are in Firebug you will see the readyState == 4 and status == 200 (not that I check for that). I usually never need to be spoon fed but I just don't understand why I am not getting the values back I need from the listener, or why it is never called. Also, not that this should matter really but I am approving the request on Firefox to be cross-domain, it is really for mobile so the call will not need to be have a confirmation of cross-domain, it will do that automatically.</p> <p>I hope someone can look at this and see what I overlooked. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload