December 31, 2015, 5:44am
I need to load a page dynamically via something like Ajax. How does Yii 2 handle this? Basically I just want to click a button and have the contents of another URL appear in a div on the same page. Very basic stuff, but I’m wondering if Yii has this built in somehow.
I’m trying this code below
<p><a id="ajax" class="btn btn-lg btn-success" href="<?php echo"$url"; ?>">Choose Winner</a></p>
And it’s not working. $url is the url of the page I want to load.
Can anyone help?
December 31, 2015, 8:28am
May be Pjax will be good for you? Pjax is a jQuery plugin that uses ajax and pushState
Look at examples
http://ksetrin.com/example/pjax/index (examples of code and implementations)
December 31, 2015, 4:35pm
Hmm I can’t really read that site. Why would pjax be a better solution? is my implementation far off?
January 1, 2016, 12:06pm
You want "Basically I just want to click a button and have the contents of another URL appear in a div on the same page"
Just look example
http://ksetrin.com/example/pjax/pjax-example-3 (it’s original link, because google try translate the code). You may click buttons and you see how change content in example block.
Pjax is already implemented in yii2
Less code more results
Do what you basically want