开发者

about combine ajax ,php and javascript

开发者 https://www.devze.com 2023-03-21 19:06 出处:网络
I have a main html file and I am using ajax to call another php file in same directory. Inside that php file, I 开发者_StackOverflowcall some external Javascript functions. But my javascripts functio

I have a main html file and I am using ajax to call another php file in same directory.

Inside that php file, I 开发者_StackOverflowcall some external Javascript functions. But my javascripts functions are not working. Is it not possible?

I see generated source in my web browser and it is normal. If i call those functions with using php file (without using ajax), then my functions are working and the generated source same as the previous case. Please help me.

In my html file I am using ajax as follows:

xmlhttp.open("GET","end_location_drop_down.php?q="+str,true);
xmlhttp.send();

in my php file functions as follow,

<?php

echo '<script type="text/javascript" src="../js/pointing.js"></script>'; //external script

    $btn8="'btn8'";
    $q=$_GET["q"];
        echo '<script type="text/javascript">
   nextpoint('.$at_id.'); //$at_id mean a variable,nextpoint() is my java script function
   </script>';
?>

in my JavaScript function have some image swapping functions.they can call by nextpoint(). But it didn't work.


Javascript functions are executed only when you load the page directly in a browser, as your browser is the one who interprets and executes the javascript code. However when the javascript code is in a different page and that page is being called through AJAX, there is no browser to execute the javascript code before the ajax response is sent back to you. SO it won't work.


Javascript must be executed in browser, so you must insert that script in DOM to current document. Try to insert result of ajax call to DOM.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号