"You can use CHtml::ajax in your view. It is PHP code and can not be stored in a separate javascript file.
If you want to store your function in a separate javascript file, then use JQuery.ajax (also called $.ajax).
Both CHtml::ajax and JQuery.ajax will take care of browser inconsistencies and will also help you with all the “readyState” and ActiveXObject (pure ajax) stuff. You don’t have to worry about such things anymore, just focus on the interesting parts."
Personally, I prefer putting my functions in separate javascript files, because it allows you to re-use your code. Haensel also mentioned that it makes debugging easier.