0

我有 ajax 调用,并且我正在正确获取数据。但我无法将数据分配给局部变量。我正在尝试将数据分配给 item_price。我得到的数据为 100.00 或 115.25

这是我的ajax代码

$.ajax({
              type: "get",
              url: "index.php?module=product&view=price",
              data: { code: v },
              dataType: "json",
              success: function(data) {
                    item_price = data;
                }

            });

谢谢你们,异步:错误,为我工作。

4

3 回答 3

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;
            }

        });
于 2013-01-11T05:51:51.633 回答
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;
                }

            });
于 2013-01-11T05:46:46.637 回答
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);
});
于 2013-01-11T05:54:52.393 回答