我有一个2输入形式,我想在MySQL查询的where语句中使用它来返回网页上的数据
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
success: function ()
});
});
});
</script>
</head>
我正在寻找要与MySQL服务器中的数据一起返回的表,但是页面重新加载而字段被清空
更新以添加新代码
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.post("3.16.86.231/bandi.php", {
// these are the data you are passing you will to find a way to get them from the input boxes
po: '$porder',
pn: '$pnumber'
},
});
});
</script>
</head><style>
body {
font-family:arial;
font-size:12;
}
</style>
<form action = "" method = "POST">
<body>
<table border = 3>
<tr>
<td> Purchase Order Number </td>
<td> <input type = text name = po value = "<?php echo $porder;?>" size="50" autofocus>
</tr>
<tr>
<td> Part Number </td>
<td> <input type = text name = pn value = "<?php echo $pnumber;?>" size="50">
</tr>
<tr>
<td colspan = 3>
<input type = "submit" name="send" value = "Ok" title="Click here to display values.">
<input type = "submit" name="clear" value = "Clear" title="Click here to clear text boxes.">
</td>
</tr>
</table>
</form>
答案 0 :(得分:0)
您可以用不同的方式来执行此操作,但是在两种情况下,您都需要准备好php文件并将其存储在服务器中以便可以运行它。然后,您需要找到您的php文件的网址,因此,如果您的php文件名为Script.php,则您的网址是localhost / Script.php,可以通过在浏览器中键入该网址来确认是否看到错误404或不。
找到网址后,我们就可以开始提交您的请求了。所以这是计划,您将把一些信息从html / js发送到php代码。然后,您的php代码将连接到数据库并运行sql。因此,要将信息发送到php,您可以使用表单发布方法,例如:
<form action="localhost/script.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.post("localhost/script.php", {
// these are the data you are passing you will to find a way to get them from the input boxes
name: "Donald Duck",
city: "Duckburg"
},
function(data, status){
//this is the data you are getting back and you need to find a way to put them in a table
alert("Data: " + data + "\nStatus: " + status);
});
});
});
如果要使用form post方法,则需要让您的php脚本呈现表并将数据放入其中。
还有其他方法可以做到,但这应该可以帮助您入门