1

I want to send a ajax request using post method with the XML as a response text, Is it possible, If it is possible please let me know the possible way for it.

For Ex

url : "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate"
data : {FromCurrency:"INR",ToCurrency:"AUD"}
method : GET or POST

http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=AUD

I need the response of this URL using ajax.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Santhanam
  • 348
  • 4
  • 15
  • If they support `JSONP`, you can add that switch. You have to learn how to do it, though. This [tutorial](http://www.ibm.com/developerworks/library/wa-aj-jsonp1/) isn't too bad. – Jared Farrish Jun 28 '12 at 07:07
  • Actually, you'd probably want [`CORS`](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) if that site doesn't have a `JSONP` feed. Of course, the browser has to support it too. – Jared Farrish Jun 28 '12 at 07:10
  • Without JSONP cant we render the content using some other methods?? – Santhanam Jun 28 '12 at 07:17
  • `CORS`. Or a server-routed proxy using cURL or something. It's a same-origin issue; there's only a few ways around it. – Jared Farrish Jun 28 '12 at 07:25
  • can also use a 3rd party proxy like Yahoo YQL. Can get a jsonp url set up in minutes in YQL console – charlietfl Jun 28 '12 at 07:47
  • Yup , Even I am also thinking of it. :) – Santhanam Jun 28 '12 at 07:55

3 Answers3

5

You can use YQL,

var url = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=AUD'; // website you want to scrape
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + url + '"') + '&format=json&callback=?';  
$.getJSON(yql,function(data){  
    if(data.query.results){
        var result = data.query.results.double.content.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
        alert(result);
    }
});
Jashwant
  • 28,410
  • 16
  • 70
  • 105
  • security measure...If you are appending result in your dom and if it involves `` tags. I do not know regex myself but it has been copied from some place in internet :) – Jashwant Jun 28 '12 at 07:54
  • +1 yeah..I thought about it after...never used it but looks like good idea to implement...always – charlietfl Jun 28 '12 at 07:55
  • 1
    Never knew about YQL as proxy for the same domain policy. Now I know. +1 – bart s Jun 28 '12 at 08:33
1

You can write your own script on server on the same domain that does request to the webservicex.net and returns data in any format that you want.

So, ajax request -> your server (on the same domain) -> webservicex.net

maxwell
  • 857
  • 8
  • 16
0

It seems that server does not support CORS. Then you won't be able to do this with an ajax call due to the same origin policy

bart s
  • 5,068
  • 1
  • 34
  • 55