0

Newbie here in jquery. I would like to know if is it possible to get the returned json data from someone's site and use it for my own purpose?

If you click the link below it will return a json response.

https://www.aag.com/svc/mortcalc.php?age=70&home_value=375000&_=1479367136330

To explain further, I would like to replace the age and home_value with my own data and use their functions.

Currently, here's how I do it:

$(document).on('change', '.age-range-drag', function() {
    var getVal = $(this).val(),
        getYear = 'Years Old';
    $('.age-range-output').val(getVal + ' ' + getYear);
});

$(document).on('click', '.hvr-pop-reverse', function(){
    var age = $('.age-range-drag').val(),
        hv  = $('#homevalue').val(),
        cmb = $('#mortgagebanalance').val(),
        finalValue = hv - cmb;

    var link = 'https://www.aag.com/svc/mortcalc.php?age=' + age + '&home_value=' + finalValue;
    console.log(link);
});

I don't know if it's do-able or not but I just wanted to try if someone did this before or if it's possible.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 2
    No it's not possible. If you try it (https://jsfiddle.net/Lw1q1741/) you'll see an error in the console: `No 'Access-Control-Allow-Origin' header is present on the requested resource`. This means that the URL you're requesting does not allow cross site requests - presumably to stop people stealing their data as you're trying to do. You would need to make the request on the server side to avoid the [SOP](http://en.wikipedia.org/wiki/Same-origin_policy) – Rory McCrossan Nov 17 '16 at 08:16
  • @RoryMcCrossan, thanks I really don't that I get a future issue just like what you said. – dogstring Nov 17 '16 at 08:19
  • @RoryMcCrossan - is there any possible solution you can think of? – dogstring Nov 17 '16 at 08:20
  • Yes - the solution is to make the request on the server. However I'd be very wary of leeching from another site as you are attempting to do. At best they'll notice all the traffic going to your site and block you, at worst you'll get a legal cease and desist order. – Rory McCrossan Nov 17 '16 at 08:21
  • @RoryMcCrossan, thanks so better look for another solution. – dogstring Nov 17 '16 at 08:25

0 Answers0