【发布时间】:2016-05-28 14:08:31
【问题描述】:
我无法将 json 值赋予 span 标签 实际上我正在使用 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");
}
});
});
的网页
我无法将文本值输入到 span 标签中
在我的 ajax 函数 success 块中有 **alert(res); 并且它工作正常它会产生结果**
$("#p_price").text(res.ourPrice);不工作
【问题讨论】:
-
res是一个字符串,使用dataType: "json",会解析成js对象 -
感谢天才,它现在可以工作了......简单的事情让我很生气。
-
另外请注意 GET 没有 contentType。没有发送内容正文
标签: javascript jquery html ajax