Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php JSON失败问题_Php_Html_Ajax_Json - Fatal编程技术网

Php JSON失败问题

Php JSON失败问题,php,html,ajax,json,Php,Html,Ajax,Json,我很难让AJAX/JSON函数正常工作。我有一个从下拉框中获取值的函数,但现在我想使用锚定标记来设置它的值 我认为只使用onClick事件将字符串传递给我用于下拉框的函数是很容易的,但即使数据被添加到MySQL中,我也会在JSON onFailure事件中收到警报。我尝试从onFailure事件中删除警报,但它没有添加数据。下拉列表仍然可以正常工作,没有警报。(我应该注意,删除警报也会破坏我的下拉框) 首先,我添加一个onClick事件 <a href="<?php echo Set

我很难让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')";>
3rd 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)”
调用
onFailure
是否提供任何参数?例如,在jQuery中,有3个参数可以为您提供有关错误的信息。我遇到了类似的问题,
错误
回调一直被调用,即使没有连接错误。这个问题原来是格式错误的JSON。你能确认你的JSON格式正确吗

更新

我刚刚查看了的文档,注意到
onFailure
的签名中可能有
xhr
。尝试查看
XMLHttpRequest
对象的
status
statusText
responseText
属性。这会给你一个关于哪里出了问题的线索

试试这个:

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

我认为你是对的--但是我没有得到下拉框的错误。。。另外,如果我忽略了onFailure,那么我没有将数据添加到mySQL,很抱歉,我对Mootools的理解不够,无法检查XMLHttpRequest对象。即使onFailure没有执行任何操作,只是发出警报,它也不会添加数据……伙计,我很困惑。请尝试将onFailure处理程序更改为我在上面的回答中所示的内容。
onFailure: function(xhr) {
   console.log(xhr.status, xhr.statusText, xhr.responseText);
}