tags:

views:

267

answers:

4

I am trying to call a PHP page with XmlHttpRequest (AJAX). My problem is that I have jQuery (javascript) included in my PHP page like this:

<script language="javascript" src="jquery.js"></script>
<script language="javascript">
   // my jquery code here
</script>

When I call the PHP page with XmlHttpRequest it fails! That is, the response only shows the PHP content but jQuery is not working! When I access that PHP page directly it works.

So, how can I fix this problem?

+2  A: 

You probably have your jquery code like this:

$(document).ready(
      function() { //something magic }
);

The fact is: it won't fire if you load it through AJAX.

To run it, you simply have to remove the $(document).ready part.

You might also read a discussion about it.

Alex Bagnolini
A: 

i have tried to remove $(document).ready part but it is still not working...........how can i fix that please let me know in detail..........

testkhan
Fix what? You still haven't defined what you mean by `not working`.
Darin Dimitrov
@testkhan because you are new and might not know, please add/edit the original rather than add more answers.
Mark Schultheiss
suppose i have <script language="javascript">$(document).ready(function(){alert("page loaded");});</script>but it not alerts........so how can i fix this issue
testkhan
A: 

i have tell you that i have follwoing in my php page

<script language="javascript" src="jquery.js"></script>
<script language="javascript">
my jquery code here
</script>
<?php
php code here
?>

but when i call this php page with xmlhttprequest it shows me only php result but the javascript is not working than how can i fix this ...........i.e javascript should work after loading page with xmlhttprequest

testkhan
Please use the `comments` section or update your original question. The `answers` section is well... for answers.
Darin Dimitrov
A: 

Javascript cannot be loaded via a xmlHttpRequest call as the javascript is registered during the page load, you need to load all javascript during the initial load

Lyon