Khan Luke Khan Luke - 9 months ago 15
PHP Question

Can an Ajax function birth another Ajax function?

I have a .live Ajax function (let's call this x) which executes onclick and connects to the database with a
url: myphpvalues.php.

Inside this php I have added another Ajax .live function (let's call this y) to be output once the user clicks the first Ajax link.

Is this allowed?


First, .live has nothing to do with AJAX. It allows us to trap a user event (click, hover, etc) on controls that do not yet exist in the DOM. If you are using a version of jQuery later than 1.7, then .live has been replaced with .on (essentially the same syntax). If a little foggy, please read this. Basically, if you didn't use .on() the jQuery code would not bind to the clicked element because the element didn't exist when the binding was attempted.

Also, if you are a little foggy on AJAX, please review this before continuing.

Because AJAX allows a javascript routine to request/receive data from a back-end (PHP) file, there is no need to use AJAX within that back-end file -- it's already PHP (or ASP.Net or whatever) and can include (or whatever) routines from other PHP files.

However, if you are asking if you can return new javascript/jQuery code back to the originating HTML/js page, yes you can. You can send back any html/js/css code that you like.

And can this new code include another AJAX code block? Yes it can. Give it a try! You will probably need to use .on() again, though.