jQuery ajax post请求突然不起作用,

时间:2013-08-02 08:31:29

标签: ajax jquery zend-framework2

我的ZF2应用程序中有一个jQuery ajax调用。它刚刚起作用。突然间它不再起作用了。即使我在请求中放置了一个不存在的操作,它也不会像之前那样给出服务器错误。它似乎没有提出要求。

控制台中绝对没有错误。一切正常,直到我提出请求。这是它的功能:

$('.expand').click(function(){
    var CCID = $(this).parent().attr('id');
    CCID = parseInt(CCID);

    console.log(CCID);                                   // Works

    if($.inArray(CCID,$expanded) > -1){
        foldin(CCID);
    } else {
        console.log('Works up to here.');                // Works
        $.post('admin/expand', {
            id: CCID
        },function(data){
            console.log('Doesn\'t log this.');           // Doesn't work
            if(data.hasOwnProperty('info')){     
                console.log('sup');
                expand(data.info);
            } else {
                console.log('Can\'t find customer info.');
            }
        },'json'); 
    }
});

就像我之前说过的那样,绝对没有错误,并记录了我评论过的所有内容。希望我犯了一个愚蠢的错误,你可以发现它。已经过了很多次,找不到它。

如果有人想看到它,我会在我的控制器中添加动作,但是post请求似乎甚至没有找到它,因为如果我给它一个虚假的动作它不会给出错误。< / p>

编辑:以下是一些额外信息

所以我根据评论者的要求添加了一个失败处理程序,它返回了:

failed [Object, "parseerror", SyntaxError]

在SyntaxError中它显示“意外令牌&lt;”,但是.js文件中没有。我找不到它告诉我它找到它的行/文件的位置。这可能会有所帮助。

这是我在控制器中调用的动作。但似乎根本没找到它:

public function expandAction(){
    $request = $this->getRequest();
    $response = $this->getResponse();

    if($request->isPost()){ 
        $post_data = $request->getPost();
        $CCID = $post_data['id'];
        $customer = $this->getCustomerTable()->getCustomer($CCID);
        $response->setContent(\Zend\Json\Json::encode(array(
            'info'      => $customer,
        )));    
    }

    return $response;
}

1 个答案:

答案 0 :(得分:1)

Arun P Johny教会我使用Google Chrome开发者工具中的“网络”标签来解决问题。从那里我可以看到路径'admin / expand'应该'展开'。

可能是一个本地化的答案,但我觉得他建议使用网络选项卡足以提供答案。也许在某些时候对其他人有帮助。

相关问题