成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

jquery提交表單的問題

瀏覽:64日期:2024-06-07 14:34:42

問題描述

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)擊提交:

jquery提交表單的問題

打開form.php頁面,卻是一片空白,echo無法輸出內(nèi)容。

jquery提交表單的問題

想實(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)文章: