我有一个ajax调用,我正在正确地获取数据。但我无法将数据分配给局部变量。我正在尝试将数据分配给item_price。我的数据为100.00 OR 115.25
这是我的ajax代码
$.ajax({
type: "get",
url: "index.php?module=product&view=price",
data: { code: v },
dataType: "json",
success: function(data) {
item_price = data;
}
});
谢谢大家,async:false,为我工作。
答案 0 :(得分:2)
试试这个
var item_price;
$.ajax({
type: "get",
async: false, //If you need synchronous requests, set this option to false
url: "index.php?module=product&view=price",
data: { code: v },
dataType: "json",
success: function(data) {
item_price = data;
}
});
答案 1 :(得分:0)
$.ajax({
type: "get",
url: "index.php?module=product&view=price",
data: { code: v },
dataType: "json",
success: function(data) { //console.log(data);/*get your price index and assign*/
item_price = data.your_price_index;
}
});
答案 2 :(得分:0)
$.post('index.php', { module: product, view: price, code: v }, function(data)
{
var item_price;
item_price = data;
});
otherwise try this
$.post('index.php', { module: product, view: price, code: v }, function(data)
{
$("#My_Div").html(data);
});