处理jQuery的Ajax表单与PHP提交 [英] Processing Jquery Ajax form submit with php

查看:156
本文介绍了处理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? :)

这篇关于处理jQuery的Ajax表单与PHP提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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