php - 问题

标签 php javascript jquery ajax json

我如何将这个变量添加到上面的代码中?我需要传递这两个变量。我试过了,但代码没有像我预期的那样工作(警报不适用于更改)。

        name: $('#name').val(),
        email: $('#email').val()


<script type="text/javascript">
    jQuery(document).ready(function() {
        $.ajax("valid.php", {
            type: "POST",
            dataType: "json",
            name: $('#name').val(), //here??
            email: $('#email').val() //here??
            success: function(step) {

                if (step.first) {
                    alert("fdsgdfg");
                }
                if (step.second) {
                    alert("dfgdfg");
                }

            }
        });
    });
</script>

谢谢!

最佳答案

将另一部分添加到您的 ajax 调用中,称为“数据”。

<script type="text/javascript">
jQuery(document).ready(function() {
    $.ajax("valid.php", {
        type: "POST",
        dataType: "json",
        data: { name: $('#name').val(), email: $('#email').val() },
        success: function(step) {

            if (step.first) {
                alert("fdsgdfg");
            }
            if (step.second) {
                alert("dfgdfg");
            }

        }
    });
});

或者:

$.ajax({
    type: "POST",
    url: "some.php",
    data: "name=John&location=Boston",
    success: function(msg){
        alert( "Data Saved: " + msg );
    }
});

关于php - 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5628743/

相关文章:

javascript - 搜索 Json 数组

jquery - 如何使更改内容中的多个链接实例发挥作用?

javascript - Jquery Spinner 箭头未加载(可见性)

php - 如何在 C++ 中加密数据并在 PHP 中解密?

php - div 溢出滚动 block 内的表格

javascript - 无法使用jquery调用json结果

javascript - 有关 iMacros 的验证码问题

javascript - 单击后如何随机化图像?

javascript - AJAX/jQuery/PHP - AJAX 表单处理程序 "Illegal invocation"

php - 准备好的语句在 mySQL/PHP 中不起作用