qtip中的jquery表单没有用ajax提交

时间:2015-12-16 04:14:06

标签: javascript php jquery ajax qtip2

我在获取此ajax表单以在qtip内提交时遇到问题...它确实提交但它忽略了e.PreventDefault()并且只是在浏览器中加载。此外,它不会禁用提交按钮,因此它甚至不会被调用代码。我尝试在成功中运行它:功能和事件:...在这件事情上的任何帮助都将非常感激。

JS:

    var editgallerysubmit    = $("#EditGallerySubmit");
var editgalleryform      = $("#EditGalleryForm");
var editgalleryresults   = $('#EditGalleryResults');

//Edit Gallery Form


//Edit Form When Hovering Over Gallery Name
$('.EditGallery').on('click', function (e) {
    e.preventDefault();
});

$('.EditGallery').each(function()
{


    $(this).qtip({
        content:  {
            text: "Loading...",
            ajax: {
                url:$(this).attr('href'),
                type: "GET",
                success: function(data, status) {   
                this.set('content.text', data);

                }                
            }
        },
        hide: {
            fixed: true,
            delay: 100
        },
        events: {
            render: function(event, api) {
                editgalleryform.bind('submit', function(e) {

                        $.ajax({
                            url: editgalleryform.attr('action'),
                            data: editgalleryform.serialize(),
                            type: 'post',
                            success: function(data, status, jqXHR) {

                            },
                            beforeSend: function() { editgallerysubmit.attr('disabled', ''); },
                            complete: function() { editgallerysubmit.removeAttr('disabled'); }
                        });

                        e.preventDefault();
                });
            }
        },
        style: 'wiki'
    });
    $(this).qtip('click', true);
});

PHP:

    $MemberGalleriesQuery = $bapcity->query("SELECT * FROM CroMemberRetailGalleries WHERE UserID='".$_SESSION['user_id']."' ORDER BY GalleryID DESC");
            $MemberGalleriesCount = $MemberGalleriesQuery->num_rows;

            if ( $MemberGalleriesCount ) 
            {
                $BaseHeight = 150;
                $GalleriesBoxHeight = $BaseHeight + ( 20 * $MemberGalleriesCount );
                echo '
                <div id="ManageGalleries" style="height: '.$GalleriesBoxHeight.'px" align="center">
                <div id="ManageGalleriesHeader">Manage Galleries</font></div><br><br>
                <font color="#000000"><b>Click Gallery To Edit</b></font><br><br>
                ';

                while($GalleryData = $MemberGalleriesQuery->fetch_assoc())
                {
                    echo '>> <b><a class="EditGallery" href="Crowork.Backend/Crowork.EditGallery.php?gallerykey='.$GalleryData['GalleryID'].'">'.$GalleryData['GalleryName'].'</a></b> <<<br>';
                }

                echo '<br><br></div>';
            }
            $MemberGalleriesQuery->free();

表格PHP文件:

    <form id="EditGalleryForm" action="Crowork.Backend/Crowork.EditGallery.php?action=DoEditGallery&gallerykey=<?php echo $GalleryData['GalleryID']?>" method="post">
    <table border="0" width="100%">
    <tr>
        <td colspan="2" align="center"><font size="-1"><b>NOTE:</b> Letters & Numbers Only</font></td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><input type="text" name="GalleryName" size="30" value="<?php echo $GalleryData['GalleryName']?>"></td>
    </tr>
    <tr>
        <td align="right" colspan="2">
            <input type="hidden" name="OriginalGalleryName" value="<?php echo $GalleryData['GalleryName']?>">
            <input type="hidden" name="GalleryID" value="<?php echo $GalleryData['GalleryID'] ?>">
            <input id="EditGallerySubmit" type="submit" name="EditGallery" value="Edit Gallery">
        </td>
    </tr>
    </table>
    </form>

所有JAVASCRIPT代码的工作除了本部分处理表格之外的其他部分。

    editgalleryform.bind('submit', function(e) {

                    $.ajax({
                        url: editgalleryform.attr('action'),
                        data: editgalleryform.serialize(),
                        type: 'post',
                        success: function(data, status, jqXHR) {

                        },
                        beforeSend: function() { editgallerysubmit.attr('disabled', ''); },
                        complete: function() { editgallerysubmit.removeAttr('disabled'); }
                    });

                    e.preventDefault();
            });

1 个答案:

答案 0 :(得分:0)

尝试在提交按钮上绑定click事件,例如

editgallerysubmit.click(function() {
   $.ajax({ /** You ajax code */ });
   return false;// to prevent page reload                       
});

如果动态创建form,则需要使用绑定点击事件,如

// var editgallerysubmit will not work here bcoz it is dynamically created and your js rendered previously
$('#EditGallerySubmit').click(function() {
   $.ajax({ /** You ajax code */ });
   return false;// to prevent page reload                       
});