为什么这个POST变量是通过AJAX Null发送的? (jquery的/ PHP) [英] Why is this POST variable sent via AJAX Null? (jquery/php)

查看:78
本文介绍了为什么这个POST变量是通过AJAX Null发送的? (jquery的/ PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此javascript用于加载更多功能。当单击按钮#moreg时,它会从load.php中获取固定数量的元素。

This javascript is for a "load more" functionality. That grabs a fixed number of elements from load.php when a button #moreg is clicked.

$(function(){
    $("#moreg").click(load);
    var countg = -1;
    load();


    function load() {
        var num = 1;
        countg += num;
        $.post( "load.php", 
                {'start_g': 'countg', 'name':'<?=$name?>' }, 
                function(data){
                    $("#posts").append(data);
                }
        );
    }
});

在load.php中只需执行 var_dump($ _ POST ['start_g' ]);
产生一个空变量。

in load.php simply doing a var_dump($_POST['start_g']); yields a null variable.

不太有帮助......我做错了什么?

Not too helpful...what am I doing wrong?

推荐答案

在使用POST请求发送的参数映射中,不必引用键(但它不会引用区别):

In the map of parameters that get sent with the POST request, the keys do not have to be quoted (but it doesn't make any difference):

$.post("load.php", {
    start_g: countg, 
    name: '<?=$name?>' 
}, function(data) {
    $("#posts").append(data);
});

我还从 countg ,因为你试图使用变量的值。如果它被引用,你只需传递字符串countg而不是名为 countg 的变量的值。

And I've also removed the quotes from countg, because you're trying to use the value of a variable. If it's quoted, you're simply going to pass the string "countg" rather than the value of the variable named countg.

这篇关于为什么这个POST变量是通过AJAX Null发送的? (jquery的/ PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆