douou6807 2013-12-09 15:00
浏览 75
已采纳

使用jQuery和$ .ajax将变量传递给PHP

I have a jQuery php script which accesses a database and echoes back html to fill a div on my page. It uses the following code.

function myCall() {
    var request = $.ajax({
        url: "ajax.php",
        type: "GET",
        dataType: "html"
    });

    request.done(function (msg) {
        $("#divholder").html(msg);
    });

    request.fail(function (jqXHR, textStatus) {
        alert("Request failed: " + textStatus);
    });
}

What I need to do is also send a variable through to the script so it knows what to look for in the database. I have been searching but I can't seem to find quite the right answer. Any help greatly appreciated.

Regards.

  • 写回答

2条回答 默认 最新

  • duankuiyuant3940 2013-12-09 15:03
    关注

    You can send the parameter like this :

    function myCall() {
        var request = $.ajax({
            url: "ajax.php?param1=" + 'parameter',
            type: "GET",            
            dataType: "html"
        });
    
        request.done(function(msg) {
            $("#divholder").html(msg);          
        });
    
        request.fail(function(jqXHR, textStatus) {
            alert( "Request failed: " + textStatus );
        });
    }
    

    And get the parameter with $_GET

    Or you can send the parameter with POST (look at data : Ajax jQuery)

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器