I put a Ajax link using the following code:
echo chtml::ajaxLink('GO', 'http://localhost/index.php?r=user/delete', array('method'=>'POST'));
But, regardless of giving the second parameter as URL i,e ‘http://localhost/index.php?r=user/delete‘. It generates link with the current URL in the browser not the URL I just specified.
What is the issue? How could I create AJAX link? Google several hours but can’t solve the issue.
Any kind of help is highly appreciated.
First of all, you should always try and create normalized urls.
But i think your doubt lies in the
#that is generated/appended. If you go and check the source of yii ajaxLink you’ll see this:so if you don’t set the
hrefproperty of theatag in thehtmloptionsarray, the#will be appended.You should also understand that yii uses jquery, so if you check out the source of the page, you’ll see at the bottom, how jquery is used to carry out an ajax request, your actual url that is called will also be seen in that script. So the third option/parameter in
ajaxLinkis for options for jquery’sajaxfunction. You can create better ajax links using this option.Regardless of where(which controller) your url points to in your project, the action associated with that url will be called.
So anyway, you can modify your code like this if you want the url to be shown and not a
#:To make better ajax links i would suggest going through jquery’s ajax documentation. There is an option for a
successfunction, that you can use to let the user know that the operation was completed.Hope this helps, don’t hesitate to leave comments if i haven’t answered your question completely.