Hello all,
I have a view accessed (using pretty urls) via:
http://localhost/my-app/event-parent/create
Ok, so I have another view with a java event that is supposed to open the above view as modal:
$JSCode = <<<EOF
function(){
$('#modal').modal('show')
.find('#modalContent')
.load('{URL}');
}
EOF;
$JSCode = str_replace('{URL}', Url::toRoute(['/event-parent/createl']), $JSCode);
So the above Jquery is being called, but when the modal window pops up it’s empty.
Here is the modal code
<?php
Modal::begin([
'header'=>'<h4>Create Event</h4>',
'id'=>'modal',
'size'=>'model-lg',
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
Never mind! Had a typo!
had a rogue l on the end of the word create, the below now works.
$JSCode = str_replace('{URL}', Url::toRoute(['/event-parent/create']), $JSCode);
I still have an issue.
Ok so I went by this video
And the idea is that I press submit on my modal window, and it supposed to submit the form, close the modal, and refresh the background via Ajax.
It’s falling over for me as I am pressing the submit button, then the browser will go directly to event-parent/create and display 1 (meaning the form submitted successfully)
[b]
So I guess the question here, how do I make the submit a background task that does not redirect the current view?[/b]
If it helps here is the code I am using in Jquery on my event-parent/create _form.php:
<?php
$script = <<< JS
$('form#{$model->formName()}').on('beforeSubmit', function(e)
{
var \$form = $(this);
$.post(
\$form.attr("action"), //serialize Yii2 form
\$form.serialize()
)
.done(function(result) {
if(result == 1)
{
$(document).find('#modal').modal('hide');
$.pjax.reload({container:'#fullCalendarPJax'});
}else
{
$(\$form).trigger("reset");
$("#message").html(result.message);
}
}).fail(function()
{
console.log("server error");
});
return false;
});
JS;
$this->registerJs($script);
?>
i answered a similar question the other day.
http://www.yiiframew…post__p__280230
you are probably telling the controller to redirect to a page. You can either remove the redirect line if this action will only be done via ajax/pjax or catch the pjax/ajax request and tell it to skip the redirect.