[英]Jquery Mobile - Download wont start
我遇到以下問題:
我希望用戶可以單擊HTML表單中的按鈕,然后開始下載。
Button使用POST方法調用名為“ working.php”的新php文件。
在working.php中,它生成一個文件並將其保存在我的服務器上。 之后,客戶可以下載文件。 在桌面版本上,它可以工作,但是在JQuery中它不起作用,我也不知道為什么:(
這是我的index.php代碼:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mobile</title>
<link rel="stylesheet" type="text/css" src="styles.css" />
<link rel="stylesheet" href="themes/sl_theme.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-position="inline">
<h1>Mobile</h1>
</div>
<div data-role="content">
<a href="#"><img src="../imgs/header.png"/ style="max-width:100%;"></a>
<form action="../working.php" method="post">
<input name="sc_url" type="text" size="50" class="textbox"> <br /> <br />
<input type="submit" value="GO">
</form>
</div>
<div data-role="footer">
<h1>© 2014 by ###</h1>
</div>
</div>
這是來自working.php的代碼
function savefile($id, $title) {
$dir = "files";
$file = file_get_contents($id);
$thetitle = "";
$titlelen = strlen($title) - 2;
$thetitle = substr($title, 1, $titlelen);
$thetitle = str_replace("/", " - ", $thetitle);
$thetitle = str_replace("\\", " - ", $thetitle);
if(strlen($thetitle) === 0) {
die('<html>
<head>
<link href="_styles.css" type="text/css" rel="stylesheet" media="all">
</head>
<body>
<div id=content>Sorry, but I cannot find a Track/Trackname :/ <br /> <br />
<a href="index.php" style="text-decoration: underline;">Home</a> </div>
</body>
</html>');
}
$filename = $dir . "/" . $thetitle . ".mp3";
file_put_contents("$filename", $file);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: public');
header('Content-type: audio/mpeg');
header("Content-Transfer-Encoding: binary");
header('Content-Length: '.filesize("$filename"));
readfile("$filename");
}
當我單擊按鈕時,它僅顯示空白頁面(working.php),但下載不會開始。
誰能幫我嗎?
問候,帕斯卡
jQuery Mobile默認在表單上使用AJAX行為,要進行下載或上載需要完整的帖子,您應該使用屬性
data-ajax="false"
所以表單不使用ajax行為
<form action="../working.php" method="post" data-ajax="false">
<input name="sc_url" type="text" size="50" class="textbox"> <br /> <br />
<input type="submit" value="GO">
</form>
如果要全局禁用,則應使用jquery全局對象,有關更多信息,請參見此處:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.