0

I have a simple AJAX call being made which sends JSON to my server and gets a JSON response.

I have found various posts here which look like the same issue, but I can't get the final piece to work.

jQuery.ajax({
  type: "POST",
  dataType: "json",
  contentType: 'application/json',
  cache: false,
  url: 'https://someURL.com',
  data: JSON.stringify({
    "brand": jQuery("#input_1_1_1").val(), 
    "model": jQuery("#input_1_1_2").val(), 
    "colour": jQuery("#input_1_1_3").val(), 
    "size": jQuery("#input_1_1_4").val() 
  }),
  success: function(data) {
    var result = JSON.stringify(data);
    console.log(result);
    console.log(result.Table1.Price);
  }
});

console.log(result); returns:

{
  "Table1": [{
    "Id": 213,
    "Brand_Name": "Ray-Ban",
    "Model_Code": "0RB2219",
    "Color_Code": "1289AF",
    "Lens_Width": "59",
    "Bridge_Size": "13",
    "Temple_Length": "140",
    "Suggested_Retail_Price": 181,
    "Price": 104.54,
    "Image": "https://my.luxottica.com/myLuxotticaImages/RB/0RB2219__1289AF_890x445.jpg",
    "Prescription_Lenses": 1,
    "Varifocal": 1,
    "ClearStd": 1,
    "SunglassesStd": 1,
    "Light_Sensitive": 1,
    "ClearRB": 1,
    "SunglassesRB": 1,
    "Varilux": 1,
    "BlueLight": 1
  }]
}

console.log(result.Table1.Price); returns:

Unable to get property 'Price' of undefined or null reference

I have tried various variations, but all seem to return undefined.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Steve Newton
  • 1,046
  • 1
  • 11
  • 28

0 Answers0