[UPHPU] run javascript inside ajax php

Von Fugal von at fugal.net
Mon Dec 13 16:17:34 MST 2010


<quote name="Merrill Oveson" date="Mon, 13 Dec 2010 at 15:47 -0700">
> What is the event that is triggered when a php file in loaded from ajax.
> 
> All I need is an event.
> 
> This works:  print "<input onclick=\"displayExpiration('y')\"
> type=\"radio\" name=\"licenseExpires\" value=\"1\"
> checked=\"checked\">";
> 
> It calls displayExpiration() which is present on the php file calling
> creating the ajax php file.

This is not how ajax works. There is no "ajax event" that gets called
automatically. What you do have is an ajax library, which makes the http
request to the server asynchronously, with which you register a callback
to get called on completion. It depends on the ajax library you are
using, but essentially you define the callback in the same place you
create the ajax call in the first place.

As for running javascript at ajax completion, you can either have the
ajax response be a snippet of javascript that immediately gets
evaluated, or you can have your callback invoke a function that is
loaded with the main page. I'm not sure if "onload" events and the like
would work with an ajax loaded piece of HTML, I kinda think they don't,
but I haven't researched it by any means. This coming from the fact that
the ajax response usually is not a full html page, but rather just a
snippet of html that gets inserted into *the* (already existing) page.

Hope that helps clear things a little.
-- 
Von Fugal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : http://plug.org/pipermail/plug/attachments/20101213/0ef81990/attachment.bin 


More information about the PLUG mailing list