用ajax发送数据,并保存在PHP的jQuery [英] jquery using ajax to send data and save in php

查看:136
本文介绍了用ajax发送数据,并保存在PHP的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

日安即时通讯正在试图从一个窗体发送或获取数据,然后使用jQuery,然后阿贾克斯发送数据到PHP页面,应该将其保存在数据库中,我怎么能做到这一点的jQuery和使用Ajax做它,任何帮助会做,谢谢!

HTML页1将使用jQuery AJAX将数据发送到PHP页面

 <形式GT;
       名称:<输入类型=文本NAME ='名'>
       电子邮件:LT;输入类型=文本名称=电子邮件>
       性别:<选择名称=性别>
       <期权价值='男'>男性< /选项>
       <期权价值='女'>女< /选项>
       < /选择>
       消息:< textarea的名字='约'>< / textarea的>
 < /形式GT;
 

PHP页面2,将在第1页的形式免费获赠数据

 < PHP
回声 
 $ _ POST ['名称'];
 $ _ POST [电子邮件];
 $ _ POST ['性别'];
 $ _ POST ['约'];
;
?>
 

任何帮助,这个项目将帮助我们极大地感谢!

(更新) 这是我尝试使用jQuery的,但到了网址,我认为这不是很安全。

  $(文件)。就绪(函数(){
    $(#聊天)。点击(函数(){
        $(#内容)的负载(a.php只会)。
    });


    $(#发送)ajaxSubmit会(网址:{url:a2.php,键入:后'})。

    });
 

解决方案

您可以使用下面的code:

 变种形式=新FORMDATA($('#form_step4')[0]);
form.append('的view_type','addtemplate');
$阿贾克斯({
    键入:POST,
    网址:savedata.php
    数据:表格,
    缓存:假的,
    的contentType:假的,
    过程数据:假的,
    成功:功能(数据){
        //警报(---+数据);
        警报(设置已经成功地更新。);
        window.location.reload(真正的);
    }
});
 

在这里savedata.php是在其中您可以做的事情DB文件名

Good day im am trying to send or get data from a form and then using jquery and then ajax to send the data into a php page that should save it in the database how can i do it in jquery and use ajax to do it, any help will do and thanks!

HTML page 1 that will use jquery ajax to send data into the php page

 <form>
       Name:<input type='text' name='name'>
       E-mail:<input type='text' name='email'>
       Gender:<select name='gender'>
       <option value='male'>male</option>
       <option value='female'>female</option>
       </select>
       Message:<textarea name='about'></textarea>
 </form>

PHP page 2 that would recieve the data from the page 1 form

<?php
echo "
 $_POST['name'];
 $_POST['email'];
 $_POST['gender'];
 $_POST['about'];
";  
?>

any help with this project would help us greatly and thanks!

(update) This is the jquery that i tried to use but it went to the url and i think that is not very safe

    $(document).ready(function(){
    $("#chat").click(function(){
        $("#content").load("a.php");
    });


    $("#send").ajaxSubmit({url: 'a2.php', type: 'post'})

    });

解决方案

you can use following code :

var form = new FormData($('#form_step4')[0]);
form.append('view_type','addtemplate');
$.ajax({
    type: "POST",
    url: "savedata.php",
    data: form,
    cache: false,
    contentType: false,
    processData: false,
    success:  function(data){
        //alert("---"+data);
        alert("Settings has been updated successfully.");
        window.location.reload(true);
    }
});

where savedata.php is the file name in which you can do the the DB things

这篇关于用ajax发送数据,并保存在PHP的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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