[英]Call link to modal on successful Ajax call
If I wanted to pop up a particular modal currently I'd add this HTML and click the link... 如果我现在想弹出一个特定的模态,我将添加此HTML并单击链接。
<a data-deploy-menu="notification-modal-3" href="#">Demo</a>
However I want to remove link and call the modal on a successful ajax call. 但是我想删除链接,并在成功的ajax调用中调用模式。 Somethinkg like the below, but unsure how to do it. 类似于以下内容,但不确定如何执行。 Please can you help? 请你帮忙
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);
}
});
});
The modal html is as follows... 模态html如下...
<div id="notification-modal-3" data-menu-size="345" class="menu-wrapper menu-light menu-modal">
<h1 class="center-text">Test</h1>
</div>
Edit : I sort of got this working.. 编辑:我有点工作了。
So I added the a href link back in. For example... 因此,我重新添加了href链接。例如...
<a id="notification-modal-4" data-deploy-menu="notification-modal-3" href="#"></a>
so the link doesnt actually show on the page then in the ajax call I used 所以该链接实际上并没有显示在页面上,然后在我使用的ajax调用中
$('#notification-modal-4').click();
but would appreciate if there is a better way to do this... 但如果有更好的方法可以做到这一点,将不胜感激...
Basically you can do this in you ajax success code: (hopyfully I did not missunderstand) 基本上,您可以在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);
}
},
With the controlling of the modal within the ajax call, you do not need any (auto-)link-clicking. 通过在ajax调用中控制模态,您不需要任何(自动)链接单击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.