![](/img/trans.png)
[英]$.post is not working in combination with $J = jQuery.noConflict();
[英]Cant make my upload form work using 2 versions of jQuery despite jQuery.noConflict()
我有一個網頁,其中包含2種不同的形式,第一種是用於上傳圖片(應該提供新上傳的圖片的鏈接),第二種是“常規”表格,可以添加產品到數據庫,在其中我使用第一種形式給出的鏈接。 問題是我使用引導程序的jQuery,並且上載表單使用1.7.2版本(不必說,有沖突。)
一旦我點擊“發送”按鈕,它應該顯示一個加載欄並顯示“ 100%”,然后顯示圖像URL,而上傳過程是在另一個名為“ upload.php”的文件中完成的,問題是,甚至盡管我使用了'jQuery.noConflic();' 它仍然繼續將我重定向到upload.php,那里什么也看不到,但是我找不到問題...
這是上傳表格:
<form id="myForm" action="upload.php" name="upload" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="col-md-4 control-label" for="filebutton">Uploader une image</label>
<div class="col-md-3">
<input id="filebutton" name="filebutton" class="input-file" type="file">
<div id="progress">
<div id="bar"></div>
<div id="percent">0%</div >
<br />
<div id="alerte"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="envoyer"></label>
<div class="col-md-3">
<button type="file" value="envoyer" id="formenvoyer" name="myfile" class="btn btn-primary">Envoyer</button>
</div>
</div>
</div>
</form>
這是PHP文件:
<?php
$output_dir = "img/";
if(isset($_FILES["myfile"]))
{
//Filter the file types , if you want.
if ($_FILES["myfile"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
//move the uploaded file to uploads folder;
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $_FILES["myfile"]["name"]);
echo "<p>Uploaded File :<br />http://grindhouseleather.esy.es/admin/img/".$_FILES["myfile"]["name"]."</p>";
}
}
?>
這是JS:
jQuery = jQuery.noConflict();
jQuery(document).ready(function()
{
var options = {
beforeSend: function()
{
$("#progress").show();
//clear everything
$("#bar").width('0%');
$("#alerte").html("");
$("#percent").html("0%");
},
uploadProgress: function(event, position, total, percentComplete)
{
$("#bar").width(percentComplete+'%');
$("#percent").html(percentComplete+'%');
},
success: function()
{
$("#bar").width('100%');
$("#percent").html('100%');
},
complete: function(response)
{
$("#alerte").html("<font color='green'>"+response.responseText+"</font>");
},
error: function()
{
$("#alerte").html("<font color='red'> ERROR: Impossible d'uploader les fichiers</font>");
}
};
$("#myForm").ajaxForm(options);
});
我錯過了什么 ? 先感謝您 !
您不應該將jQuery
用於jQuery.noConflict();
。 更改為:
jq = jQuery.noConflict();
原因是:
jQuery = jQuery.noConflict();
上面的代碼沒有區別。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.