Php Ajax多输入不显示所有数据?
我被多重输入卡住了。我的代码没有显示所有数据。下面是我正在使用的html:Php Ajax多输入不显示所有数据?,php,jquery,ajax,Php,Jquery,Ajax,我被多重输入卡住了。我的代码没有显示所有数据。下面是我正在使用的html: <form id="matkul" class="form-horizontal" method="POST"> <table class="table table-condensed"> <thead> <tr> <th>Matakuliah</th>
<form id="matkul" class="form-horizontal" method="POST">
<table class="table table-condensed">
<thead>
<tr>
<th>Matakuliah</th>
<th>Data Lain</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</form>
<button id="post" type="submit">Save</button>
<button id="get">Get Data!</button>
下面是ajax post代码,但当它已经发送数据时,警报不会显示所有数据
<script type="text/javascript">
$(document).ready(function(){
$("#post").click(function(){
string = $("form").serialize();
alert(string); // this alert is normal, show all data
$.ajax({
type: "GET",
url: "/save.php",
data: string,
success: function(data){
alert("Success!"+data); //this not normal, not show all data
}
});
});
});
</script>
最新的反应是这样的
Array
(
[fmatakuliah] => Wide Area Network
[fdata] => matakuliahdetail.asp?session_id=xxbKiKJawuyrbaaiJ3Kabybabi3JJiKJrJyb3wiuKbbry0JbKiKbKr0yyrKK15933511&mk=52323605&kur=2010
)
我的问题是如何显示所有数据并将其保存到数据库?看起来您需要将AJAX类型从GET to POST更改为:
$.ajax({
type: "POST",
url: "/save.php",
data: string,
success: function(data){
alert("Success!"+data); //this not normal, not show all data
}
});
嗯,我可以肯定的是,在保存到db时使用GET不是正确的方法。另外,我不太懂php,只懂javascript…所以我在这方面帮不了你多少忙;数据是save.php页面返回的内容。行字符串=$(“形式”).serialize();将表单中的所有输入序列化,使其成为save.php中使用的字符串。请与我们分享您的save.php内容。save.php是什么样子的。什么代码从save.php输出数据。你所能做的就是
print\r($\u-GET)
tryecho-json\u-encode($\u-GET)
然后成功:函数(数据){console.log(数据);}
然后检查控制台日志
print_r($_GET);
Array
(
[fmatakuliah] => Wide Area Network
[fdata] => matakuliahdetail.asp?session_id=xxbKiKJawuyrbaaiJ3Kabybabi3JJiKJrJyb3wiuKbbry0JbKiKbKr0yyrKK15933511&mk=52323605&kur=2010
)
$.ajax({
type: "POST",
url: "/save.php",
data: string,
success: function(data){
alert("Success!"+data); //this not normal, not show all data
}
});