Reputation: 4564
I know how to post using $.ajax method. I have a form that posts data to a payment API this is what the response looks like:
<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>
as you can see the total of transactions is 0,
so step 1 make the post request using $.ajax, then on success: I want to do $('#results'),html('the total transactions are: '+numberoftransactions);
any ideas/suggestions ? thank you
Upvotes: 0
Views: 1256
Reputation: 282
I guess rahul has answered your question so I just wanted to add that if you're trying to pass data to the url and get back response accordingly then you could take advantage of the data property while making ajax request. suppose you're trying to get xml response according to user profile so you have to pass user id to the url to get accurate response. You can just do it like this
$(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);
}
});
});
Hope this helps or may be I didn't understand properly, what you were looking for.
Upvotes: 1
Reputation: 7663
you can try something like this
$(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);
}
});
});
try finding required value in responseText
for more information please visit this link
Upvotes: 2