繁体   English   中英

成功调用Ajax时,将链接链接到模式

[英]Call link to modal on successful Ajax call

如果我现在想弹出一个特定的模态,我将添加此HTML并单击链接。

<a data-deploy-menu="notification-modal-3" href="#">Demo</a>

但是我想删除链接,并在成功的ajax调用中调用模式。 类似于以下内容,但不确定如何执行。 请你帮忙

jQuery.ajax({

        url: "http://localhost/timesheets/mobile/add-timesheet.php",
        type: "POST",
        data: form.serialize(),
        crossDomain: true,
        datatype: "json",
        cache: false,
        success: function (data) {
            var jsArray = JSON.parse(data);
            console.log(jsArray);
            if ($.trim(jsArray.success) === 'yes') {
                $('#notification-modal-3').load;
            }
        },
        error: function (xhr, thrownError) {
            console.log(xhr.status);
            console.log(thrownError);
        }
    });
});

模态html如下...

    <div id="notification-modal-3" data-menu-size="345" class="menu-wrapper menu-light menu-modal">
    <h1 class="center-text">Test</h1>
    </div>

编辑:我有点工作了。

因此,我重新添加了href链接。例如...

<a id="notification-modal-4" data-deploy-menu="notification-modal-3" href="#"></a>

所以该链接实际上并没有显示在页面上,然后在我使用的ajax调用中

$('#notification-modal-4').click();

但如果有更好的方法可以做到这一点,将不胜感激...

基本上,您可以在ajax成功代码中执行此操作:(希望我没有误会)

success: function (data) {
   var jsArray = JSON.parse(data);
   console.log(jsArray);
   if ($.trim(jsArray.success) === 'yes') {

       // fill up the modal with some content if it is dynamicaly
       $('#notification-modal-3').html('thank you');
       $('#notification-modal-3').show();
       // do some cleanup if needed like hide it if needed
       setTimeout(function() {
           $('#notification-modal-3').html('');
           $('#notification-modal-3').hide();
       }, 1000);

   }
},

通过在ajax调用中控制模态,您不需要任何(自动)链接单击。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM