weixin_33724659 2010-04-26 15:57 采纳率: 0%
浏览 87

如何从onFailure事件中删除警报?

我在Ajax/JSON函数上遇到了一点问题......我想用这个函数从下拉框中获取值,并使用一个锚标记来设置它的值。

我一直以为使用onClick事件将字符串传递给用于下拉框的函数是很容易的,而且数据也被成功添加到了MySQL中,但是我却在JSON onFailure事件中得到了警报。我试着从onFailure事件中删除警报,但是它就不添加数据了。没有警报的时候,下拉框会继续工作,且运行正常。(注意,删除警报也破坏了我的下拉框)。

第一,添加onClick事件…

<a href="<?php echo Settings::get('app.webroot'); ?>?view=schedule&action=questions" onmouseout="MM_swapImgRestore();" onmouseover="MM_swapImage('bre','','template/images/schedule/bre_f2.gif',1)" onclick="assignCallType('testing')";>

第二,检查main.js.php:

function assignCallType(type) {
  alert(type);
  new Request.JSON({
    url: "ajax.php",
    onSuccess: function(rtndata, txt) {
      if (rtndata['STATUS'] != 'OK')
        alert('Status was not okay');
    },
    onFailure: function() {
      alert("onFailure")
    }
  }).get({
    'action': 'assignCallType',
    'call_type': type
  });
}

第3,Ajax.php:变量返回PHP,值被添加到MySQL中,但我在JSON onFailure事件中得到了警报:

if ($_GET['action'] == "assignCallType") {
    if ($USER->isInsideSales()) {
        $call_type = $_GET['call_type'];
        $_SESSION['callinfo']->setCallType($call_type);
        $_SESSION['callinfo']->save($callid);
        echo json_encode(array('STATUS'=>'OK'));
    } else {
        echo json_encode(array('STATUS'=>'DENIED'));
    }
}

究竟哪里出错了?这与工作下拉列表之间唯一的区别是在函数调用上,我使用的是onchange="assignCallType(this.value)"。

  • 写回答

1条回答 默认 最新

  • weixin_33733810 2010-04-26 16:55
    关注

    Does the callback for onFailure provide any arguments? For example in jQuery there are 3 arguments that can give you information about the error. I ran into a similar problem where the error callback kept getting called even though there was no connection error. The problem turned out to be badly-formed JSON. Can you confirm that your JSON is well-formed?

    UPDATE

    I just checked out the documentation for Request and noticed that onFailure can have xhr in its signature. Try taking a look at the status, statusText, and responseText attributes of the XMLHttpRequest object. That will give you a clue as to what's going wrong.

    Try this:

    onFailure: function(xhr) {
       console.log(xhr.status, xhr.statusText, xhr.responseText);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP