Sk Asraf Sk Asraf - 6 months ago 16
Ajax Question

span tag text not change using JQuery ajax

i cant give json value to span tag
actually i am using jquery ajax function

var productId = $("#product_id").text();
var city = $("#spn-deliveryloccookies").text();

$.ajax({
url: '/Product/est_time',
type: 'GET',
data: { 'city': city, productid: productId },
contentType: 'application/json; charset=utf-8',
success: function (res) {
//your success code
alert(res);
//$("#p_price").html("");

$("#p_price").text(res.ourPrice);
},
error: function () {
alert("some error");
}
});
});


after that it produce result
firebug result
and the web page having a





i cant give the text value in to span tag

in my ajax function success block there have **alert(res); and it work fine it produce result**

image link
but

$("#p_price").text(res.ourPrice); not work

Answer

You need to parse the json string to javascript object. Then only you access its properties.

  $("#p_price").text(JSON.parse(res).ourPrice);