Jquery移动页面无法打开php文件

时间:2017-03-15 14:34:36

标签: php html jquery-mobile

我正在尝试将表单从jquery-mobile页面提交到php文件进行处理,但每当我按下提交按钮时,它都会显示“错误加载页面”对话框。

我已尝试查看w3schools website表单提交示例,并且我非常确定我的代码是相同的。这是我的代码。

的index.html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Jquery Mobile</title>

<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">

<!-- Include the jQuery library -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Include the jQuery Mobile library -->
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

<style>
  .ui-content {
  margin-top:150px;
  margin-left:500px;
  margin-right:500px;
}

/* For mobile screens */
@media screen and (max-width: 480px) {
    .ui-content{
        margin:0px;
}
</style>
</head>

<body>
<div data-role="page" id="chat">
<div data-role="header"><h1>Welcome to the Streamline Chat App</h1></div>
  <div data-role="main" class="ui-content">
   <h3>Select a username to continue</h3>
    <form method="post" action="login.php">
     <label for="username" >Username:</label>
     <input type="text" id="username" name="username">
     <input type="submit" data-inline="true" value="Submit">
    </form>
  </div>
</div>
</body>
</html>

的login.php

<?php
 $username = $_POST['username'];

 echo $username;
?>

我想知道我做错了什么。请帮帮我。两个文件都在同一目录中

1 个答案:

答案 0 :(得分:0)

我从另一篇帖子here

得到了答案

只需将data-ajax="false"添加到表单标记

即可
<form method="post" action="login.php" data-ajax="false">
  <label for="username" >Username:</label>
  <input type="text" id="username" name="username">
  <input type="submit" data-inline="true" value="Submit">
</form>