I’m sure that I made a mistake, but simply can’t find it. And since I’ve never used AJAX in Yii (an fairly never in PHP at all) I fear that without help from someone else, I’ll be looking for it till next Christmas!
class ZleceniaController extends Controller
{
public function actionAJAXGetParams()
{
if(isset($_POST['ajax']))
{
echo date('H:i:s');
Yii::app()->end();
}
else throw new CException('Not an AJAX!');
}
}
Problems? Two:
[list=1][]In response I got my own exception text (Not an AJAX!) and I’m stuck! What? CHtml::ajaxSubmitButton doesn’t submit as AJAX?[]’#section_2_div is not being updated! Even if I see (and click OK) message displayed upon complete, it still remains with the loader.[/list]
Thanks! As I said, I have no experience with using AJAX calls and just copied this part from another piece of code generated by Yii, mistakenly assuming, that this array is auto-filed by Yii performing AJAX request. Of course, I should use: Yii::app()->request->isAjaxRequest in that place.
Now works fine, but how to change that example code from being ajaxbutton to pure AJAX call initiated upon page load? Tired this:
This has the same effect of an ajax button, or you can put on onmouseover of something, whereever you want.
You can use firebug for test if the request was sent or not, if it was sent if it was successfully and so on (I think is rather impossible to debug ajax without firebug).
And is a bit strange to use both update and success at a time, you should choose one of them (in your case, update is ignored).
If you use ajaxsubimtbutton you have to use submit form, and you have to use $htmlOptions[‘params’], and $htmlOptions[‘return’], or you have to set ajax options, witch are same
Thanks! That explains much! As I wrote, I want this AJAX request to be fired when page finishes loading. With a little help from the other post, I mentioned and with a lot of help from you (thanks!) I was able to mange this with such code:
Although this is a bit off-topic, can you give me any tip, how to debug AJAX requests in firebug? I have it installed but I am as new to it as to AJAX request and up to now I was using it only to analyse HTML / CSS code of various elements of various pages. Don’t know how to debug JS, jQuery or AJAX calls in it.
Thanks, but I know that. This was put there only to debug and after I get this stuff working with your help, I removed any messaging from this code.
It isn’t the same, because you are generating ajax button! I don’t want button, I want AJAX request to be fired automatically, when page finishes to load it contents. It’s a huge difference (at least for me), because your solution requires user reaction (click the button, ajax link or whatever), while mine doesn’t.
May be you were referring to non ability to set $live value as TRUE or FALSE on a component basis, for that I have the solution posted, its almost the same as changing $live=TRUE to $live=FALSE as default argument, Check it out. http://www.yiiframework.com/forum/index.php?/topic/14…175
Thanks Amit for your post. No, my problem was rather based on that I never used AJAX in Yii and was lacking of some basic knowledge about it. Thanks again.