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

AJAX response with HTML code in Yii2?

Lord.
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)
D
Dmitry Bay, 2018-11-12
@dentxt

Specifically in your case

ob_start(); 
     Modal::begin();
echo 'contnetn';
Modal::end();
    ob_start(); 

$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()

M
Maxim Lagoysky, 2018-11-12
@lagoy

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