I am fairly new to web based development. How can i get a JSON/HTTP response from a 3rd party URL using Javascript/JQuery/AJAX? Also how do i access and use the information contained it? I have learned how to parse once i get the information. It is the fetching part i am struggling with. Please try to explain wit any third party URL.
Asked
Active
Viewed 2,436 times
0
-
Yes. Basic JQuery ajax tutorial describe those scenarios with examples. – Lasitha Benaragama Apr 03 '14 at 05:56
1 Answers
1
$.ajax({
url: 'http://xx.xx.xxx.xxx',
dataType: 'jsonp',
data: {
xxx: {
"xxx" : "xxx",
}// <-- if you have data use this
},
success: function(res) {
console.log(res);
}
});
This is the basic sample of cross domain call using jsonp. Think this might help.
update - Without json you can use below code
$.ajax({
url: 'http://xx.xx.xxx.xxx',
// if you using below proxy passes use --> url: '/xxx',
type:'POST', //or GET
dataType: 'json',
crossDomain : true,
data: {
//data goes with request
},
success: function(res) {
//do stuff with res
}
});
Then you will need to set the Access-Control-Allow-Origin
header correctly to allow the other server.
for apache server its like that
ProxyPass /xxx http://xx.xxx.xxx.xxx:xxx/xxx
ProxyPassReverse /xxx http://xx.xx.xxx.xxx:xx/xxx

Lasitha Benaragama
- 2,201
- 2
- 27
- 43
-
1This will only work if the 3rd party API implements JSONP. Many (probably most) don't. – Barmar Apr 03 '14 at 05:54
-
1
-
@Tux thanks my mistake it is using jsonp is the name used as '?jsonp=' part of url. Corrected. Thanks – Lasitha Benaragama Apr 03 '14 at 06:02
-
@Barmar i edited the answer for Json also. Thanx for the tip buddy. – Lasitha Benaragama Apr 03 '14 at 06:12
-