我看到很多類似的問題就在這裏,但沒有完全像什麼,我經歷。jQuery Mobile的PHP形式後返回undefined
我有一個簡單的聯繫人頁面上我的網站能正常工作的桌面版本,但是當我設置了使用jQuery移動網頁時發佈它只是返回未定義的移動版本。
下面的形式,隨後在PHP。
<html>
<head>
<title>John's Website | Contact Me</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src="../js/menu.js"></script>
<LINK REL="SHORTCUT ICON" HREF="../favicon.ico">
</head>
<body>
<div data-role="page">
<h2>Fill out the form below to contact me.</h2>
<form action="contact.php" method="post">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" size="40" /><br />
<label for="lastName">Last Name:</label>
<input type="text" id="lastName" name="lastName" size="40" /><br />
<label for="userEmail">Your Email:</label>
<input type="text" id="userEmail" name="userEmail" size="40" /><br />
<label for="message">Message:</label>
<textarea id="message" name="message" cols="30" rows="5"></textarea><br />
<input data-role="none" type="submit" value="Submit"></input>
<input data-role="none" type="reset" value="Reset"></input>
</form>
</div>
</body>
</html>
和PHP
<?php
$host="localhost"; // Host name
$username="Idont"; // Mysql username
$password="thinkso"; // Mysql password
$db_name="john"; // Database name
$tbl_name="contact"; // Table name
//connect
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//gather vars and sanitize input
$first_name = htmlentities($_POST['firstName']);
$last_name = htmlentities($_POST['lastName']);
$email = htmlentities($_POST['userEmail']);
$message = htmlentities($_POST['message']);
$date_stamp = date("Y-m-d h:i:s");
$first_name = mysql_real_escape_string($_POST['firstName']);
$last_name = mysql_real_escape_string($_POST['lastName']);
$email = mysql_real_escape_string($_POST['userEmail']);
$message = mysql_real_escape_string($_POST['message']);
if(empty($_POST['firstName']) && empty($_POST['lastName']) &&
empty($_POST['userEmail']) && empty($_POST['message'])){
echo 'You did not fill out all fields. Please go back and enter all info.';
}
//write contents to db.
$sql = "INSERT INTO $tbl_name (firstName, lastName, email, date, message)
VALUES ('$first_name', '$last_name', '$email', '$date_stamp', '$message')";
if(mysql_query($sql)){
$content = "Your message has been sent. /n Click <a href="index.php">here</a> to go
back to the home page.";
} else {
$content = mysql_error() . $date_stamp . 'Unable to send your message. Try again
later.';
}
?>
<html>
<head>
<title>John's Website | Contact Me</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.mobile-1.1.0.min.js"></script>
<LINK href="../js/jquery.mobile-1.1.0.min.css" rel="stylesheet" type="text/css">
<LINK REL="SHORTCUT ICON" HREF="../favicon.ico">
</head>
<body>
<div data-role="page">
<div data-role="header">its loaded</div>
<div data-role="content"><?php echo $content; ?></div>
</div>
</body>
</html>
我打算再加工使用PDO的代碼和更OO的風格,但該頁面應該工作。這是我第一次使用JQM,所以我認爲我錯過了一些東西。
請不要使用'mysql_ *'函數編寫新代碼。他們不再維護,社區已經開始[棄用程序](http://goo.gl/KJveJ)。查看[*紅色框*](http://goo.gl/GPmFd)?相反,你應該瞭解的方法制得的語句(http://goo.gl/vn8zQ),並請使用[PDO](HTTP – gorelative
我不想讓你把這種錯誤的方式,但你看了整個帖子?我提到,在最後一段。 –
同時它無關,與我問的問題。該代碼仍然有效,即使它是不是最好的做法。 –