質問

よし、以前は尋ねました...石鹸プロトタイプaap aapactionヘッダー質問(残念ながらハイパーリンクできません。「2」リンクの担当者が十分ではありません...以下を参照)

それは決してうまくいきませんでした。プロトタイプと関係があると思いますが、0をOnsuccessとして返します。コンテンツタイプのUTF-8のフォーマットはわかりません。今、私がストレートjavaScriptに戻って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を決して呼びません。 RECORTER request.responsexml.ChildNodes [0] .ChildNodes [1] .ChildNodes [3] .ChildNodes [5] .textContent;

必要な値を取得し、FireBugにいる場合はReadyState == 4およびStatus == 200が表示されます(私はそれをチェックしません)。私は通常、スプーンで給餌する必要はありませんが、リスナーから必要な価値を取り戻していない理由や、それが呼ばれない理由を理解していません。また、これは本当に重要ではありませんが、私はFirefoxに対するクロスドメインのリクエストを承認しています。実際にはモバイル向けであるため、クロスドメインの確認を必要とする必要はありません。自動的に行います。

誰かがこれを見て、私が見落としているものを見ることができることを願っています。ありがとう!

役に立ちましたか?

解決

onreadyStateChangeは、サーバーへの非同期リクエストに対してのみ呼び出され、コードは同期リクエストを送信しています。

Open CallにTrueに3番目のパラメーターを設定します(または、デフォルトがtrueとして3番目のパラメーターを削除します)。

request.open("POST", "http://iaspub.epa.gov/uvindexalert/services/UVIndexAlertPort?wsdl", true);

http://msdn.microsoft.com/en-us/library/ms536648(vs.85).aspx

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top