0

Regarding this code:

var htmlitems = "";

$.getJSON("getjsonvin.aspx?v=1B3LD76M48N121862&c=1410", function (data2) {

    var options = JSON.stringify(data2[0].dealer_options);

    options = options.replace("[", "");

    options = options.replace("]", "");

    options = options.replace(/['"]+/g, '')

    var optres = options.split(",");

    for (var i = 0; i < optres.length; i++) {

        htmlitems = htmlitems + "<li>" + optres[i].toString() + "</li>";

    }

    alert(htmlitems);

    return htmlitems;

});

alert(htmlitems);

The FIRST alert shows me my html <li> in the alert box that grabbed from screwy json... (the json comes to me screwed up so I have to do all the replacing crap...) BUT I'm getting what I want in the htmlitems variable (FIRST ONE)

The SECOND alert, it's like htmlitems is blank again??? Hopefully someone in la, la programming land can tell me what's wrong?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Tim Maxey
  • 749
  • 6
  • 13
  • 1
    I doubt the JSON comes to you screwed up, and if it does, fix it on the server, don't mess around with it like you are. – ndugger Jan 26 '16 at 19:48
  • unfortunately the json does come that way.... http://api.dealertrend.com/1410/inventory/vehicles.json?vin=2T3YF4DV6BW059583 look for "dealer_options" so when I'm looping through json and get to dealer_options "dealer_options":["179 hp horsepower","2.5 L liter inline 4 cylinder DOHC engine with variable valve timing","4 Doors","4-wheel ABS brakes","Automatic Transmission","..... I need the variable set so I can use it later. But you can't with async, so I did a work around, thanks... – Tim Maxey Feb 02 '16 at 13:28

0 Answers0