Answer the question
In order to leave comments, you need to log in
How to insert php code into js event?
Hello!
I took the form _form.php formed by gii as a basis.
I created a button in it with an onclick event and an ajax request.
In success, you need to create a field, how can this be done?
I tried to create a div, but it did not work to push the php code into div.innerHTML.
How can I do that ? Or would you recommend another way to do it?
Answer the question
In order to leave comments, you need to log in
No need to shove php into js. There are only 3 options:
1. When sending an ajax request, return the html generated by php in response
return $this->renderAjax('_my_new_field',['somedata'=>$somedata]);
and process this html in success Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question