处理jQuery的Ajax表单与PHP提交

问题描述:

最近我一直在挣扎与jQuery和Ajax试图提交表单他们。我有一个用户名字段和密码字段以及一个提交按钮非常简单的形式。什么形式是应该做的是,一旦该表单提交的信息将被阿贾克斯发送到PHP文件,然后添加该表格值到数据库。我所挣扎的是如何从阿贾克斯的值到PHP。这是我的code:

Recently I've been struggling with Jquery and Ajax while trying to submit forms with them. I have a very simple form with a username field and password field as well as a submit button. What the form is supposed to do is that once the form is submitted the info would be sent by Ajax to a php file which then adds the said form values to a database. What I am struggling with is how to get the values from Ajax to php. Here is my code:

$('#form').submit(function(){

var username = $('#username').val();
var password = $('#password').val();

var dataString = 'uname=' + username + '&passw=' + password;


$.ajax({

    type: "POST",
    url:'check.php',
    data: dataString,

    success: function(data){
        alert(data);//only for testing purposes
    }
});

什么躲开我是我怎么能得到dataString从这个用php?

What eludes me is how can I get the dataString from this with php?

PHP文件:

<?php
    print_r($_POST);
?>

jQuery的一部分:

jQuery part:

var dataString = 'uname=555';
$.ajax({
    type: "POST",
    url:'check.php',
    data: dataString,

    success: function(data){
        alert(data);//only for testing purposes
    }
});

让我:

所以,我只能猜测是,你不能获取你的数据在JavaScript。

So my only guess would be that you are failing to fetch your data in javascript.

还有一个想法。替换类型GET。然后在PHP文件中写了一行:

One more idea. Replace the type with "GET". Then in php file write a line:

echo $_SERVER["REQUEST_URI"];

这是什么给你的警告框? :)

What does it give you in the alert box? :)