weixin_33701251 2010-08-15 01:02 采纳率: 0%
浏览 35

jQuery Ajax返回未定义

$('.updateDescriptionProduct').click( function() {
  if ( updateProductDescription(productID, description) == 'true') {
    alert('success!');
  } else {
    alert('did not update');        
  }
});

function updateProductDescription(productID, description) {
  $.ajax({
    url: '/index.php/updateProductDescription',
    global: false,
    type: 'POST',
    data: ({productID: productID, description: description}),
    dataType: 'html',
    async:false,
    success: function(msg){
      alert(msg); 

      return msg;
    }
  });
}

The function itself says true, but my click event comes back as undefined.

  • 写回答

1条回答 默认 最新

  • YaoRaoLov 2010-08-15 01:04
    关注

    the return applies to the callback. Try setting a variable in the initial function and setting the value in the callback, then returning it?

    function updateProductDescription(productID, description) {
        var ret = false;
        $.ajax({
              url: '/index.php/updateProductDescription',
              global: false,
              type: 'POST',
              data: ({productID: productID, description: description}),
              dataType: 'html',
              async:false,
              success: function(msg){
                ret = msg;
              }
        });
        return ret;
    }
    

    I haven't ever done an async call but it seems this should work. Let me know if it doesn't.

    评论

报告相同问题?

悬赏问题

  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示