简体   繁体   English

jQuery中没有使用AJAX POST请求保存的数据

[英]No data saved with AJAX POST request in jQuery

I'm having some problems with a jQuery form submission. 我在jQuery表单提交时遇到一些问题。 Here is my jQuery code; 这是我的jQuery代码;

$.ajax({
    type: 'POST',
    url: 'chat/password.php',
    data: $("#roomform").serialize(),
    success: function(msg) {
        alert( "Data Saved: " + msg );
    }
});

However, it will only ever alert the following text; 但是,它只会警告以下文本;

Data saved:

With no data. 没有数据。

The PHP that returns data is; 返回数据的PHP是;

if(!$roompass) {
    echo "0";
}else{
    if(!$check) {
        echo "0";
    }else{
        if($roompass == $check['password']) {
            echo "1";
        }else{
            echo "0";
        }
    }
}

Any help is appreciated, thanks! 任何帮助表示赞赏,谢谢!

You have to active ajax only when you submit the form and prevent the default browser form submission. 仅在提交表单时才必须激活ajax,并阻止默认的浏览器表单提交。

$('#roomform').sumbit(function(e) {
   e.preventDefault();
   $.ajax({
       async: true,
       type: 'POST',
       url: 'chat/password.php',
       data: $("#roomform").serialize(),
       success: function(msg) {
           alert( "Data Saved: " + msg );
       }
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM