0

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.

Ke3rthi
  • 11
  • 3

1 Answers1

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