如果改变输入值,jQuery提交表单
I'm used jquery.form plugin, it's working and good but when change input value.. it's submitted good! but redirect me to my uploader.php file, i don't want redirect me, i need to get result in div.result,
我使用jquery。表单插件,运行良好,但当输入值改变时。这是提交好!但是把我重定向到上传者。php文件,我不想重定向,我需要得到div。result,
to understand me, please look to my code:
要理解我,请查看我的代码:
HTML
HTML
<form id="uploader" action="uploader.php" method="post" enctype="multipart/form-data">
<input id="file" type="file" name="uploader" value="" draggable="true">
<input name="submit" type="submit" class="submit" value="Upload">
<div class="result"></div>
</form>
uploader.php file:
上传。php文件:
<?php
if( isset($_POST['submit']) and $_SERVER['REQUEST_METHOD'] == "POST" ){
echo 'done!';
}
?>
jQuery code:
jQuery代码:
jQuery(document).ready(function() {
$('#uploader').change(function(){
$(".result").html('');
$(".result").html('wait..');
$("#uploader").ajaxForm({
target: '.result',
success: function()
{
$('.result').hide().slideDown('fast');
$('#uploader')[0].reset();
},
});
});
});
I need to echo 'done' in .result div, i don't want to redirect me to uploader.php page.
我需要在。result div中返回“done”,我不想将我重定向到uploader。php页面。
4 个解决方案
#1
0
Is it actually doing anything when you change the input value? I mean is it submitting the form? Or does that only happen when you click the submit button?
当你改变输入值时,它实际上做了什么吗?是提交表格吗?还是只在单击submit按钮时才会发生?
It seems to me that your script doesn't really do anything. It listens for an onchange event on the form element, but that event, in my experience, is never fired on a <form>
. So you just have an HTML form submitting with no aid of script.
在我看来,你的剧本并没有什么作用。它侦听表单元素上的onchange事件,但在我的经验中,该事件从未被触发为
On top of that I'm not sure you can submit a multipart/form-data form with script, for security reasons. Maybe I'm wrong about that, but either way, how about using an iframe instead?
最重要的是,出于安全考虑,我不确定是否可以提交带有脚本的多部分/表单数据表单。也许我错了,但是不管怎样,用iframe代替怎么样?
<form id="uploader" action="uploader.php" method="post" enctype="multipart/form-data" target="resultframe">
<input id="file" type="file" name="uploader" value="" draggable="true">
<input name="submit" type="submit" class="submit" value="Upload">
<div class="result"><iframe name="resultframe" onload="$('.result').hide().slideDown('fast');"></iframe></div>
</form>
To be honest I don't know if an onload works on an iframe these days, I haven't tried it in years. Failing that, remove <div class="result">
and the corresponding </div>
and put them into the output of uploader.php, along with the animation script.
老实说,我不知道现在iframe上的onload是否能用,我已经很多年没有尝试过了。否则,删除
和相应的更多相关文章
- PHP基础之脚本传参
- 如何在表单操作中执行PHP函数?
- phpBB3导入帖子的Python脚本
- PHP脚本在我的Wordpress文件中。请解码或帮助我删除它。
- AJAX调用在JavaScript中运行PHP脚本
- 通过Bash脚本语言逃避MYSQL命令行。
- 是否可以从另一个sql脚本中的存储过程调用sql脚本?
- 程序猿(媛)Shell脚本必备技能之一: 在Linux下如何自动备份mysql
- shell脚本中mysqldump的基本使用