jquery提交表單的問題
問題描述
index.html的代碼:
<html>
<head>
<meta charset="utf-8">
<script src="jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btn").click(function () {
$.ajax({
type:"post",
url:"form.php",
data:{
bookname:$("#bookname").val(),
press:$("#press").val()
},
async: true,
success: function(msg) {
alert("提交成功!"+msg);
}
});
});
});
</script>
</head>
<body>
<div style="text-align: center; margin-top: 50px;">
<form id="form1">
圖書名:<input type="text" id="bookname" /><br>
出版社:<input type="text" id="press" style="margin-top: 15px;" /><br>
<input id="btn" type="button" value="提交" style="margin-top: 27px;" />
</form>
</div>
</body>
</html>
form.php的代碼:
<?php
$a = $_POST["bookname"];
$b = $_POST["press"];
echo $a;
echo $b;
?>
運(yùn)行index.html,在表單里輸入并點(diǎn)擊提交:
打開form.php頁面,卻是一片空白,echo無法輸出內(nèi)容。
想實(shí)現(xiàn)的效果是:
1、通過ajax提交表單又不跳轉(zhuǎn)頁面。
2、php頁面能接收到ajax提交的表單數(shù)據(jù),并通過echo輸出表單數(shù)據(jù)并顯示在php頁面。
目前php頁面是能接收到ajax提交的表單數(shù)據(jù),因為可以返回數(shù)據(jù)到參數(shù)msg??墒峭ㄟ^echo輸出表單數(shù)據(jù)并顯示在php頁面,卻是一片空白,究竟是哪里出錯了呢?
問題解答
回答1:那后臺的雙引號變成單引號
回答2:看控制器里面
相關(guān)文章:
1. php多任務(wù)倒計時求助2. 為何 localStorage、sessionStorage 屬于html5的范疇,但是為何 IE8卻支持?3. win10 python3.5 matplotlib使用報錯4. MySQL的聯(lián)合查詢[union]有什么實(shí)際的用處5. mysql 遠(yuǎn)程連接出錯10060,我已經(jīng)設(shè)置了任意主機(jī)了。。。6. html5 - css3scale和rotate同時使用轉(zhuǎn)換成matrix寫法該如何轉(zhuǎn)換?7. 默認(rèn)輸出類型為json,如何輸出html8. PHP訂單派單系統(tǒng)9. python的正則怎么同時匹配兩個不同結(jié)果?10. 數(shù)組排序,并把排序后的值存入到新數(shù)組中
