AJAX代码
$.ajax({
type: "POST",
url: "../updateDB.php",
data: {
field: idValue[0],
newValue: newValues,
firstName: idValue[2],
lastName: idValue[3]
},
success: function(){
}
});
PHP File (updateDB.php)
$field = $_POST['field'];
$newValue = $_POST['newValue'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
我想把JQUERY文件中的值传递给PHP文件。帮助! !谢谢你!
试试这样写:
$.post( 'updateDB.php', { 'field' : idValue[0], 'newValue' : newValues, 'firstName' : idValue[2], 'lastName' : idValue[3] }, function( data ) { $('#response').html( data ); });
在您的页面中包含以下内容(以显示服务器响应):
<div id="response"></div>
然后将以下代码放入PHP脚本中,以将张贴的值转储回网页(以给您一个可视化的队列,表明事情正在工作):
echo "<pre>" . print_r( $_REQUEST, true ) . "</pre>";
您可以使用
访问单个值$field = $_REQUEST['field']; $newVal = $_REQUEST['newValue'];
如果你在PHP文件中使用Ajax函数,那么你可以这样使用
data: {
field: '<?=$field?>',
newValue: '<?=$newValue?>',
firstName: '<?=$firstName?>',
lastName: '<?=$lastName?>'
},
让我知道这有帮助吗?