dongpu42006096 2014-01-25 12:43
浏览 37

没有获得ajax查询到我的php页面的成功回调

Edit: changed $.alert() to alert()

I've got a file, planner.php that uses JQuery to send an ajax request to the same page. Using the debugger, I can see that the php correctly gets the request, accesses my database, and then sends the data. However even after sending it I get no success callback in the javascript. What's wrong?

JQuery:

$(function()
{
    $.post('planner.php', {"want": "keys"}, success_func, 'json');
});

function success_func(result)
{
    //This is never called :(
    alert("Worked");
}

PHP:

<?php
require_once "./php/couch.php";
require_once "./php/couchClient.php";
require_once "./php/couchDocument.php";

if (count($_POST) > 0 && array_key_exists("want", $_POST)) {
    $couch_dsn = "http://localhost:5984/";
    $couch_db = "subjects";
    $client = new couchClient($couch_dsn, $couch_db);
    header('Content-type: application/json');
    $response = $client->getView('subject_views', 'keys');
    echo json_encode($response);  //This all seems to work fine
}
?>

It's that simple. All of the PHP code there is just accessing couchDB which you don't have to worry about because I know that $response is set correctly.

  • 写回答

4条回答 默认 最新

  • duanjianshen4871 2014-01-25 12:50
    关注

    This is probably be cause there is no such thing like $.alert(), use simple alert() instead.

    Also your success_func is declared below the ajax call, move it up before $.post();

    EDIT:

    as the function is declared, there is no need to type it before executing.

    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接