php输入表单后 从数据库读出其他项_然后自动添加到表单...,ajax和php输入多个表单输入到数据库...

这是一个简单的AJAX演示:

HTML

jQuery的

// listen for user to SUBMIT the form

$(document).on('submit', '#my_form', function(e){

// do not allow native browser submit process to proceed

e.preventDefault();

// AJAX yay!

$.ajax({

url: $(this).attr('action') //

,async: true //

,cache: false //

,type: $(this).attr('method') //

,data: $(this).serialize() //

,dataType: 'json' //

,success: function(data){

// Server responded with a 200 code

// data is a JSON object so treat it as such

// un-comment below for debuggin goodness

// console.log(data);

if(data.success == 'yes'){

alert('yay!');

}

else{

alert('insert failed!');

}

}

,error: function(){

// There was an error such as the server returning a 404 or 500

// or maybe the URL is not reachable

}

,complete: function(){

// Always perform this action after success() and error()

// have been called

}

});

});

PHP process.php

/**************************************************/

/* Uncommenting in here will break the AJAX call */

/* Don't use AJAX and just submit the form normally to see this in action */

// see all your POST data

// echo '

'.print_r($_POST, true).'
';

// see the first names only

// echo $_POST['firstname'][0];

// echo $_POST['firstname'][1];

// echo $_POST['firstname'][2];

// echo $_POST['firstname']['custom1'];

// echo $_POST['firstname']['custom2'];

/**************************************************/

// some logic for sql insert, you can do this part

if($sql_logic == 'success'){

// give JSON back to AJAX call

echo json_encode(array('success'=>'yes'));

}

else{

// give JSON back to AJAX call

echo json_encode(array('success'=>'no'));

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值