doubi1931 2010-08-27 14:02
浏览 55
已采纳

Jquery AJAX响应不起作用

For some reason this jQuery function is not working properly. Here's my code... the response div is not updating with my response.

WHEN AJAX FUNCTION IS CALLED

if ($action == 'sort') {

    echo 'getting a response';
    return 0;

}

JQuery FUNCTION

function sort() {

    $.ajax({
        type: "POST",
        url: "contributor_panel.php?action=sort",
        data:"sort_by=" + document.getElementById("sort_by").value +
             "&view_batch=" + document.getElementById("view_batch").value,
        success: function(html){

            $("#ajaxPhotographSortResponse").html(html);

        }
    });

}

DIV TO REPLACE

<div id="ajaxPhotographSortResponse"></div>
  • 写回答

2条回答 默认 最新

  • douwen2158 2010-08-27 14:20
    关注

    Move the action=sort into the data property of the $.ajax function. You're making a POST request, but appending data onto your query string like a GET request. Data only appends to the query string if it's a GET request.

    Example:

    $.ajax({
            type: "POST",
            url: "contributor_panel.php",
            data: {action:'sort', sort_by: $('#sort_by').val(), view_batch: $('#view_batch').val()},
            success: function(html){
    
                $("#ajaxPhotographSortResponse").html(html);
    
            }
        });
    

    http://api.jquery.com/jQuery.ajax/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题