How to use model popup using ajax? Can any one help for this. Here below my code. How can i apply in this code model popup? And also post data get in popup. How it possible?
app/code/Vendor/Complany/view/frontend/web/js/example.js
define([
'jquery',
'Magento_Ui/js/modal/modal'
], function (,ドルexample,modal) {
return {
exampleData:function(ajaxurl){
$("#example").click(function(e){
e.preventDefault();
$.ajax({
url:ajaxurl,
type:'POST',
showLoader: true,
dataType:'json',
success:function(){
alert('test');
}
});
});
}
}
}
);
app/cpde/Vendor/Company/view/frontend/templates/example/example.phtml
<div id="events_popup" style="display: none;" class="events_popup">
<script>
require(
['jquery','Vendor_Company/js/example'],
function(,ドルexample){
var ajaxurl = '<?php echo //My URL using block function; ?>';
example.exampleData(ajaxurl);
}
);
</script>
asked Aug 23, 2017 at 7:39
Payal Patel
1,5111 gold badge20 silver badges40 bronze badges
-
have you try with $("#events_popup") instead of $("#example")?Rakesh Jesadiya– Rakesh Jesadiya2017年08月23日 08:37:41 +00:00Commented Aug 23, 2017 at 8:37
-
@RakeshJesadiya Here $("#example") is button idPayal Patel– Payal Patel2017年08月23日 08:43:32 +00:00Commented Aug 23, 2017 at 8:43
1 Answer 1
define([
'jquery',
'Magento_Ui/js/modal/modal'
], function (,ドルexample,modal) {
var options = {
type: 'popup',
responsive: true,
innerScroll: true,
buttons: [{
text: $.mage.__('Continue'),
class: 'primary action submit btn btn-default',
click: function () {
this.closeModal();
}
}]
};
return {
exampleData:function(ajaxurl){
$("#example").click(function(e) {
e.preventDefault();
var $form = $('#form-validate');
var data = $('#form-validate').serialize();
if(!$form.valid()) return false;
$.ajax({
url:ajaxurl,
type:'POST',
showLoader: true,
dataType:'json',
data: data,
complete: function(data) {
$('#email_address').val("");
$("#events_popup").html('Thanks.').modal(options).modal('openModal');
},
error: function (xhr, status, errorThrown) {
console.log('Error happens. Try again.');
}
});
});
}
}
}
);
Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
answered Aug 23, 2017 at 10:59
Payal Patel
1,5111 gold badge20 silver badges40 bronze badges
Explore related questions
See similar questions with these tags.
default