0

$.ajax メソッドを使用して投稿する方法を知っています。支払い API にデータを投稿するフォームがあります。応答は次のようになります。

<ns2:GetTransactionsResponseType xmlns:ns2="http://www.paymentgateway.com/schema/api/2.0/service.xsd">
<Timestamp>2012-08-14T17:33:55.213+10:00</Timestamp>
<Version>2.0</Version>
<Status>Success</Status>
<total>0</total>
</ns2:GetTransactionsResponseType>

トランザクションの合計が 0 であることがわかるように、ステップ 1 で $.ajax を使用してポスト リクエストを作成し、成功したら: I want to do $('#results'),html('the total transactions are: '+numberoftransactions); any idea/suggestions ? ありがとうございました

4

2 に答える 2

2

あなたはこのようなことを試すことができます

$(function(){

    $.ajax({
         type: "GET",
         url: $uri,
         dataType: "xml",
         async: false,
         contentType: "text/xml; charset=\"utf-8\"",
         complete: function(xmlResponse) {

                // So you can see what was wrong...
                console.log(xmlResponse);
                console.log(xmlResponse.responseText);

              $("#preForXMLResponse").text(xmlResponse.responseText);
         }
    });

});

responseText で必要な値を見つけてみてください

詳細については、このリンクにアクセスしてください

XMLHttpRequest オブジェクト

于 2012-08-14T07:44:31.863 に答える
1

rahul があなたの質問に答えたと思いますので、データを URL に渡してそれに応じて応答を取得しようとしている場合は、ajax リクエストを作成するときに data プロパティを利用できることを追加したかっただけです。ユーザー プロファイルに従って xml 応答を取得しようとしているとします。正確な応答を取得するには、URL にユーザー ID を渡す必要があります。あなたはちょうどこのようにすることができます

$(function(){

$.ajax({
     type: "GET",
     url: $uri,
     data: $user_id, //this id will be passed with the request to the url as query string
     dataType: "xml",
     async: false,
     contentType: "text/xml; charset=\"utf-8\"",
     complete: function(xmlResponse) {

            // So you can see what was wrong...
            console.log(xmlResponse);
            console.log(xmlResponse.responseText);

          $("#preForXMLResponse").text(xmlResponse.responseText);
     }
});

});

これが役に立てば幸いです。または、あなたが探していたものを正しく理解していなかった可能性があります。

于 2012-08-14T10:28:13.977 に答える