html匿名函数作用域,jQuery ajax成功匿名函数作用域

1d8d1547a87574dfdda1084fcfe26cf9.png

莫回无

那是错误的方法。AJAX中的第一个A是异步的。该函数在AJAX调用返回之前返回(或至少可以返回)。因此,这不是范围问题。这是订购的问题。只有两个选项:使用选项使AJAX调用同步(不推荐)async: false;要么改变思维方式。代替从函数返回HTML,您需要传递一个回调,以在AJAX调用成功时被调用。作为(2)的示例:function findPrice(productId, storeId, callback) {    jQuery.ajax({        url: "/includes/unit.jsp?" + params,        cache: false,        dataType: "html",        success: function(html) {            // Invoke the callback function, passing the html            callback(productId, storeId, html);        }    });    // Let the program continue while the html is fetched asynchronously}function receivePrice(productId, storeId, html) {    // Now do something with the returned html    alert("Product " + productId + " for storeId " + storeId + " received HTML " + html);}findPrice(23, 334, receivePrice);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值