0

I am currently trying to obtain this JSON array from

http://d.yimg.com/aq/autoc?query=goo&region=US&lang=en-US

However, which ever I use, it does not seem to work.

Using

$.ajax({
       type: 'GET',
       url: 'http://d.yimg.com/aq/autoc?query=goo&region=US&lang=en-US',
       cache : false,
       dataType : 'json',
       success: function(data){
       alert('got it!');
       }

}

And also tried

$.getJSON("http://d.yimg.com/aq/autoc?query=goo&region=US&lang=en-US, function(data) {
        });

As well as looking into a bypass for cross domain, and I tried using a proxy, not did not work, Maybe I am implementing it wrong? I can not seem to properly obtain the data (nothing return to data).

EDITED

I used this bypass php proxy to try and bypass the missing CORS and JSONP, and it does not seem to return the data correctly either (I followed an example). The php is within my directory.

$(document).ready(function() {
    $("#tickBox").on("input", function(e) {
        'use strict';
        var tick = document.getElementById("tickBox").value;
        $.ajax({
            type: 'GET',
            url: 'http://d.yimg.com/aq/autoc?query=goo&region=US&lang=en-US',
            crossOrigin : true,
            //dataType : 'json',
            context: {},
            success: function(data){
                alert(data.ResultSet.Result[0].name);
            }
        });
    });
});
Bao Thai
  • 533
  • 1
  • 6
  • 25
  • Can you try `crossDomain:true` in your `ajax` opts? – Ataur Rahman Munna Feb 19 '17 at 07:29
  • Sorry, the originally `?format=json` is not usually there, I thought I could possibly format the URL, but even without it, it does not work – Bao Thai Feb 19 '17 at 07:31
  • @AtaurRahmanMunna I tried the `crossDomain`, it did not work unfortunately, I used my `alert` as a debug, it did not pop up. – Bao Thai Feb 19 '17 at 07:32
  • 2
    The API you're trying to get data from needs to support cross origin resources sharing (CORS) or JSONP. If it doesn't, there is no way to access it using Ajax from a browser. – Patrick Hund Feb 19 '17 at 07:34
  • https://developer.yahoo.com/javascript/json.html#callbackparam – mplungjan Feb 19 '17 at 07:35
  • 1
    @BaoThai you can try using the lib : http://www.ajax-cross-origin.com/ . remember for security reason it's not a good practice. – Ataur Rahman Munna Feb 19 '17 at 07:41
  • Possible duplicate of [jQuery AJAX cross domain](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) – Patrick Hund Feb 19 '17 at 07:41
  • @AtaurRahmanMunna Ahhhh wonderful! Hmmm, I guess I would have to use this solution temporarily. What would you say is a safer solution? Also, I am trying to access the data returned. It did returned, but data access is rather weird. – Bao Thai Feb 19 '17 at 07:48
  • I'm receiving this: `"{"ResultSet":{"Query":"goo","Result":[{"symbol":"GOOG","name":"Alphabet (...) {"symbol":"BGFV","name":"Big 5 Sporting Goods Corporation","exch":"NMS","type":"S","exchDisp":"NASDAQ","typeDisp":"Equity"}]}}`, but then I'm using IE10, so... – Bekim Bacaj Feb 19 '17 at 07:53
  • @BekimBacaj I am too, but is the way I am trying to access the data is invalid? – Bao Thai Feb 19 '17 at 07:55
  • Does coding matter if I am using chrome? @BekimBacaj – Bao Thai Feb 19 '17 at 08:02
  • @BaoThai read the accepted answer. http://stackoverflow.com/questions/466737/why-the-cross-domain-ajax-is-a-security-concern – Ataur Rahman Munna Feb 19 '17 at 08:05
  • @BekimBacaj My apologies, I meant I am also getting that JSON string. – Bao Thai Feb 19 '17 at 08:07
  • @BaoThai that's what you've requested - that's what you and everybody else will get. – Bekim Bacaj Feb 19 '17 at 08:08
  • @BekimBacaj Ah alright, thank you. – Bao Thai Feb 19 '17 at 08:13
  • @AtaurRahmanMunna hahaha, sorry. Seems like a problem has arise... The cross-domain worked with this google api I had for that last couple days, suddenly it is not working anymore. Not sure, but can't seem to find if anyone has/had the same problem as me. – Bao Thai Feb 22 '17 at 06:22

0 Answers0