你好这里有一点帮助..当我向index.php提交请求表格而不重定向到它时,如何将数据发布到页面(update.page.php)。这个想法就像向另一个页面提交消息而另一个页面接收消息而不刷新页面..但是在这种情况下提交数据库的数据我想在update.page.php中发布..我希望你能帮助我完成论文..谢谢。我没有任何代码来解决这个问题,我无法向你展示任何东西..希望你有一个解决方案.. Ps。#apole ..
答案 0 :(得分:2)
选项1:
你应该使用像这样的jquery post函数
$(selector).post(URL,data,function(data,status,xhr),dataType)
选项2: 对于更高级的实现,将update.page.php函数实现为Soap API,然后将数据发布到该API的someThing,如下所示
$client = new SoapClient("http://example.com/soapFunction.php?wsdl");
$params = array("id" => 1,"name" => "Name","description" => "Abc","amount" => 500,);
$response = $client->__soapCall("update", array($params));
答案 1 :(得分:1)
试试这个例子,它可以帮到你:
Index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function postData(){
var fname = $("#fname").val();
var lname = $("#lname").val();
var email = $("#email").val();
$.ajax({
type: 'POST',
url: 'update.page.php',
data: {"firstName":fname,"lastName":lname},
success: function(data) {
alert(data);
console.log('Data send');
//$("#display-property-address").html(data);
}
});
}
</script>
<form name="stable" method="POST" id="form">
<input type = 'text' name ='fname' id='fname'/>
<input type = 'text' name ='lname' id='lname'/>
<input type = 'email' name ='email' id='email'/>
<input type = 'button' name ='submit' value='submit' id='submit' onclick="postData()"/>
</form>
</body>
</html>
update.page.php
<?php
$firstName= $_POST['firstName'];
$lastName= $_POST['lastName'];
echo "success";
?
答案 2 :(得分:0)
你应该尝试ajax表单提交 示例代码:
$(document).ready(function(){
$("#submit").click(function(){
var email = $("#email").val();
var name = $("#name").val();
var data = 'email='+ email + '&name='+ name;
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "ajaxsubmit.php",
data: data,
cache: false,
success: function(result){
alert(result);
}
});
return false;
});
});