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;
?>
運行index.html,在表單里輸入并點擊提交:
打開form.php頁面,卻是一片空白,echo無法輸出內(nèi)容。
想實現(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. python - oslo_config2. php傳對應(yīng)的id值為什么傳不了啊有木有大神會的看我下方截圖3. python - scrapy url去重4. 關(guān)于mysql聯(lián)合查詢一對多的顯示結(jié)果問題5. 實現(xiàn)bing搜索工具urlAPI提交6. 數(shù)據(jù)庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實在是找不到哪里的問題了。7. python - Django有哪些成功項目?8. 小白學(xué)python的問題 關(guān)于%d和%s的區(qū)別9. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)10. Python從URL中提取域名
