Ajax concerns

Auto-loading articles could be done via ajaxLink(), which is an effective way to achieve this functionality.

Although, I’m worried about users who have their Javascript engine turned off. Since ajaxLink does not accept two links, and the one I provided points to an ajaxOnly action, users with older or restrictive browser cannot see those articles.

If I restructure my application to have a single gateway for returning full page / partial page, will ajaxLink() provide enough capability not to deny non-js browsers?

To get around this, I write my jquery myself (always). 90% of the time I find I need to later extend the jquery code beyond a point that the yii method supports anyways.

So far I did the same every time as well, but that feels like I can’t mine out Yii’s capabilities.

How could Yii’s (especially CHtml’s) ajax support be improved? I think Qiang would appreciate some nice ideas.

Good point. A similar though has been at the back of my mind, but isn’t a real problem yet.

Do we need some inbuilt failover?

Like Jonah, I have been handcrafting my own jQuery (mainly AJAX) stuff, so I’m not fully aware of the internals of the current limitations.

@jonah: Could you share how you get around this?

Read this:

Here is for example how you might get a link to work with and without JS:

  • jquery code



$("#updateItemSubmitButton").click(updateItem);

function updateItem(){

	//update the item with AJAX here


	alert('Updated');

	return false;

}



Now, if JS is turned off in the browser, the submit button will just submit as normal, without ajax. The server-side can detect if the submission is ajax or not. If JS is on, then when the button is clicked, it will not open the page defined in the <form> tag but rather send an ajax request.

My opinion about the best voted stack overflow answer:

This is wrong. Only hard-coded javascript means dependency. Generated js does not eliminate old http methods alone.

In an attempt to unify Yii-generated js, I’d generate them as separated pieces of code (and leave tag attributes ontouched), and rely on tag id only.

Once all pieces are together, I’d publish them in one single file within a doc ready function.

Of course, when even one piece is missing, that would cause a new file being created and downloaded each time.

For this scenario, I’d store all js-code within one file (I’m doing this right now) and send non-essential pieces as well (like preloading). In this case, all pieces should have a unique name to track its insert status.