Хорошо, ранее я спросил ... SOAP Прототип AJAX SOAPAction Заголовок Вопрос (не может гиперссылке его, к сожалению, не хватает респ для «2» ссылки ... смотри ниже)Javascript SOAP XMLHttpRequest мобильный
Который никогда не срабатывал. Я думаю, что это имеет какое-то отношение к Prototype, оно вернет 0 как onSuccess. Я не могу понять форматирование utf-8 Content-type. Теперь, если я вернусь к прямому яваскрипту и использование XMLHttpRequest
<html xmlns="http://www.w3.org/1999/xhtml">
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->Internet Options->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(
'<?xml version="1.0" encoding="utf-8"?>' +
'<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">' +
' <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
' <tns:getUVIndexAlertByZipCode>' +
' <in0 xsi:type="xsd:string">12306</in0>' +
' </tns:getUVIndexAlertByZipCode>' +
' </soap:Body>' +
'</soap:Envelope>'
);
// 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();
</script>
Это никогда не называет onreadystatechange. Если вы раскомментируете return request.responseXML.childNodes [0] .childNodes [1] .childNodes [3] .childNodes [5] .textContent;
Он получит требуемое значение, и если вы находитесь в Firebug, вы увидите ReadyState == 4 и status == 200 (не для того, чтобы проверить это). Мне обычно не нужно кормить ложкой, но я просто не понимаю, почему я не получаю обратно от слушателей ценности, или почему их никогда не называют. Кроме того, не то, что это должно иметь значение, но я утверждаю, что запрос на Firefox является междоменным, он действительно предназначен для мобильных устройств, поэтому для вызова не требуется подтверждение междоменного доступа, оно будет делать это автоматически.
Надеюсь, кто-то может посмотреть на это и посмотреть, что я пропустил. Благодаря!
Человек! Огромное спасибо. Стой мой мозг! Теперь я могу продолжить свою жизнь! –
Рад помочь! :) – Jonathan