单击li时,不使用ajax.form提交表单。给我一些解决方案
我的js代码在这里
$(document).ready(function(){
$('#sortable li').click(function() {
$("#frmgallery").submit(function(event) {
event.preventDefault();
var formdata = $(this).serialize();
alert(formdata);
$.ajax({
type: "POST",
url: "gallery.php",
data: formdata,
success: function(){alert('success');}
});
});
});
HTML就在这里
<form method="post" enctype="multipart/form-data" id="frmgallery" name="gallery" action="<?php get_template_directory();?>admin.php?page=gallery/gallery.php">
<ul id="sortable">
Query
<li class="ui-state-default" name='liindex' id="<?php echo $row['glryRecordId'];?>" >
<span style="display:none"><?php echo $row['glryRecordId'];?></span>
<img class='thumbnail' alt='' src='<?php echo get_site_url();?>/wp-content/themes/townsley/upload/<?php echo $row['glryName']; ?>' width='80' height='60'
style="border: 1px solid #D3D3D3;padding:2px;"/><input type="hidden" value="<?php echo $row['glryRecordId'];?>" name="recordId[]" />
<a href="<?php get_template_directory();?>admin.php?page=gallery/gallery.php&delid=<?php echo $row['glryRecordId'];?>" style="display:block;text-align:center" title="DELETE this image from the record" class="arial-red">Remove</a>
</li>
</ul>
</form>
请帮帮我 感谢
ajax jquery javascript
答案 0 :(得分:2)
您也应该在问题中提供HTML,但据我所知,您在event
回调中event
实际上没有任何内容可以发起submit
事件。所以基本上你应该考虑这样的事情:
$(document).ready(function(){
$('#sortable li').click(function() {
event.preventDefault();
var formdata = $("#frmgallery").serialize();
alert(formdata);
$.ajax({
type: "POST",
url: "gallery.php",
data: formdata,
success: function(){alert('success');}
});
});
});
答案 1 :(得分:0)
您可以使用Ajax Form Plugin中的ajaxForm / ajaxSubmit函数或jQuery序列化函数。
示例:强>
$("#frmgallery").ajaxForm({url: 'gallery.php', type: 'post'})
或
$("#frmgallery").ajaxSubmit({url: 'gallery.php', type: 'post'})
按下提交按钮时, ajaxForm
将发送。 ajaxSubmit
立即发送。
答案 2 :(得分:0)
您是否尝试在提交功能结束时返回false?
$("#frmgallery").submit(function(e) {
e.preventDefault();
var formdata = $(this).serialize();
alert(formdata);
$.ajax({
type: "POST",
url: "gallery.php",
data: formdata,
success: function(){alert('success');}
error: function(){alert('error');}
});
return false;
});
$('#sortable li').click(function() {
$("#frmgallery").submit();
});
同时发布您从$.ajax
电话
答案 3 :(得分:0)
$("#frmgallery").ajaxForm({url: 'gallery.php', type: 'post'})
您是否尝试在提交功能结束时返回false?
$("#frmgallery").submit(function(e) {
e.preventDefault();
var formdata = $(this).serialize();
alert(formdata);
$.ajax({
type: "POST",
url: "gallery.php",
data: formdata,
success: function(){alert('success');}
error: function(){alert('error');}
});
return false;
});
$('#sortable li').click(function() {
$("#frmgallery").submit();
});