gpt4 book ai didi

php - 通过ajax发布值时更新表字段时出错

转载 作者:行者123 更新时间:2023-11-28 02:24:54 26 4
gpt4 key购买 nike

我正在尝试通过ajax更新学生的个人资料,脚本运行良好,我得到了dataString中传递的所有值,但当通过ajax调用savebasic.php时,它没有更新字段的值。

J脚本:

<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".savestudent").click(function() {

var _firstname=$("#firstname").html();
var _lastname=$("#lastname").html();
var _gender=$("#gender").html();
var _location=$("#location").html();
var _aboutme=$("#about").html();
var _dob=$("#dob").html();

var dataString= 'fname='+ _firstname + '&lname='+ _lastname + '&gender='+ _gender + '&location='+ _location + '&about='+ _aboutme + '&dob='+ _dob ;
alert(dataString);

$.ajax
({

type: "POST",
url: "savebasic.php",
data: dataString,
cache: false,
success: function(html)
{

alert('success');
},
error: function(html)
{


}
});
});
});

</script>

savebasic.php:

<?php

include_once('controller/profile.controller.php');
$profileObject=new ProfileController();

$fname=$_POST['fname'];
$lname=$_POST['lname'];
$gender='M';
$loc=$_POST['location'];
$about=$_POST['about'];
$birth=$_POST['dob'];

$upt=$profileObject->updateUserprofile('59',$fname,$lname,$birth,$gender,$loc,$about);

?>

如果我直接在 savebasic.php 上传递值,它就可以工作。但在通过 ajax 时它什么也不做。

最佳答案

您在ajax中使用数据字段的方式是错误的。你应该这样做:

data:{'fname=': _firstname, 'lname=':_lastname,'gender=':_gender,'location=': _location}

关于php - 通过ajax发布值时更新表字段时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15109735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com