i cant give json value to span tag actually i am using jquery ajax function
我不能给跨越标签的json值实际上我使用jquery ajax函数
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 and the web page having a
之后它产生结果并且网页有一个
i cant give the text value in to span tag
我不能将文本值赋予span标记
in my ajax function success block there have **alert(res); and it work fine it produce result**
在我的ajax函数成功块中有** alert(res);它工作正常,产生结果**
$("#p_price").text(res.ourPrice); not work
$( “#p_price”)文本(res.ourPrice)。不行
1 个解决方案
#1
0
You need to parse the json string to javascript object. Then only you access its properties.
您需要将json字符串解析为javascript对象。然后只有您访问其属性。
$("#p_price").text(JSON.parse(res).ourPrice);
#1
0
You need to parse the json string to javascript object. Then only you access its properties.
您需要将json字符串解析为javascript对象。然后只有您访问其属性。
$("#p_price").text(JSON.parse(res).ourPrice);