我正在摆弄 jQuery.ajax() 和 php,我需要一些指针才能使一切正常:
这是php代码:
if(!empty($_POST["fname"])){
        $firstName = $_POST["fname"];
        echo $firstName."<br />";
    }
    if(!empty($_POST["id"])){
        $age = $_POST["id"];
        echo $age;
    }
这是jQuery代码:
jQuery("#ajaxForm").submit(function(event){
    event.preventDefault();
    var firstName = jQuery("#firstName").val();
    var age = jQuery("#age").val();
    // jQuery.ajax() - Perform an asynchronous HTTP (Ajax) request.
    jQuery.ajax({
        type: "POST",
        url: "http://localhost/profiling/index.php",
        data: {fname:firstName, id:age}
    }).done(function(result){
        alert("Your data has been submitted!" + firstName);
    });
    var result;
    console.log(result);
});
来自 jQuery 的值存在,我收到警报,告诉我数据已提交,firebug 显示 Ajax 帖子正在工作。
为什么 php 不获取我的数据并回显它?