2 回答
TA贡献1802条经验 获得超4个赞
您可以在ajax调用中附加变量,您需要在 php 页面中使用它&来分隔变量和=分配值 .i,e :
//attaching values to pass
var data = "name=" + name + "&email=" + email + "&surname=" + surname + "&Address=" + Address + "&Password=" + Password;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//if success do something here
alert("save");
}
};
var url = "asset/php/inserting.php";
request.open("POST", url, true);
//send data to php page
request.send(data);
TA贡献1773条经验 获得超3个赞
我的建议是使用 jQuery 库而不是 XMLHttpRequest。您需要在<head>HTML 部分包含一个<script>标签,以便从某些 CDN(内容交付网络)加载 jQuery 库。也添加id="f"到您的<form>标签。那么你的 Ajax 调用就可以很简单:
$.ajax({
type: "POST",
url: 'asset/php/inserting.php',
data: $('#f').serialize(), // serializes the form's elements.
success: function(msg)
{
alert(msg); // show response from the php script.
}
});
- 2 回答
- 0 关注
- 127 浏览
添加回答
举报