这似乎适用于我不需要上传的动态更改表单。
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://mediahood.net/js/ajaxfileupload.js"></script>
<script>
$(document).ready(function(){
$("#txtrform").submit(function(){
$.post($(this).attr('action'), $(this).serialize(), function(data) {
$("#col3").load("/include/txtrpbox/feed.php");
$('input#txtrinput').val('');
});
return false;
});
});
</script>
但是当我添加这个时,AJAX 失败并且表单提交正常重新加载页面。
<script type="text/javascript" src="http://mediahood.net/js/ajaxfileupload.js"></script>
<script>
$(document).ready(function(){
$("#txtrform").submit(function(){
$.post($(this).attr('action'), $(this).serialize(), function(data) {
$("#col3").load("/include/txtrpbox/feed.php");
$('input#txtrinput').val('');
});
return false;
});
function ajaxFileUpload()
{
//starting setting some animation when the ajax starts and completes
$("#loading")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
/*
prepareing ajax file upload
url: the url of script file handling the uploaded files
fileElementId: the file type of input element id and it will be the index of $_FILES Array()
dataType: it support json, xml
secureuri:use secure protocol
success: call back function when the ajax complete
error: callback function when the ajax failed
*/
$.ajaxFileUpload
(
{
url:$.post($(this).attr('action'),
secureuri:false,
fileElementId:'fileToUpload',
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}else
{
alert(data.msg);
}
}
},
error: function (data, status, e)
{
alert(e);
}
}
)
return false;
}
});
</script>
为什么?我希望我的非上传和上传表单都能正常工作。
我使用来自http://www.phpletter.com/Our-Projects/AjaxFileUpload/的脚本