dentxt2018-11-12 16:56:24
dentxt, 2018-11-12 16:56:24

AJAX response with HTML code in Yii2?

In yii2 - newbie and first problem.
I implement a simple ajax search - on the keyup event, a request is made to the controller-> BD and then in the controller in a loop, I write data to HTML tags that I store in one variable, like $response.=''
Then I return this variable and insert it into the desired block on site.
Everything works, except for the Modal::begin(); widget;
I can't write the modal code to a variable and that's the problem. Not all HTML is displayed, but only the button of the modal window.
I understand that this is the most crooked implementation, but there is really little experience in this framework.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Dmitry Bay, 2018-11-12

Specifically in your case

echo 'contnetn';

$out .= ob_get_clean();

or add a view and write your code there. But all this is wrong. But teach! 1) Json response. 2) renderAjax() 3) renderPartial()

Maxim Lagoysky, 2018-11-12

In your Action that processes ajax, return the desired view , just don't forget to create this view, and in ajax in response, catch this html and paste it where you need it, if very briefly)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question