![]() |
After makeHttpRequest how to run update javascript vars?
By making httpRequest to php script, I am able to print the output to target container. But, i need to update javascript variable after this which i am not alble to do, any suggestion?
<script..> var rate = 3.3; </script. <div id="outputDiv"> <!-- httpResponseText --> <div onMouseover="myfunc();" onclick="getNewText to replacealllthis();"> this is output by ajax http request</div> <!-- --> </div> function myfunc() { alert(rate); // rate was initially 3.3 //after onclick event the value of rate has changed to say 4.4 // but onMouseover event will still alert 3.3 so how to update this rate var // 4.4 ?? } simple solution is to create output text as <div onMouseover="myfunc(4.4);" onclick="getNewText to replacealllthis();"> this is output by ajax http request</div> ->> and myfunc alert the val However I don't want to pass param to myfunc() but use single var rate to do this event. 1. Can I ie is there a way to receive a return value from php script as well as the responseText? 2. I tried outputting <script type="..."> var rate = 4.4; </script> ... and rest of response text but all the response text willl simply be printed in the output div and the updated var rate is not run . so is there a way to make this assignment of new value to rate run? thanks |
JavaScript does not execute script tags with innerHTML, you need to eval() it. Most JavaScript libraries will do this for you.
Eric |
Quote:
Well Alien if you could be little more specific on how to use eval , would be much more help. You see the initially javascript var rating = 10 was printed after making http ajax request this value might have been changed, lets just say I need to change this var to 20, so if i print the var again like var rating = 20 from output handler function, how do I run this script? I am forced to use a function update(20) after getting the httpReq out put through javascript function which i want to avoid. Thanks. |
If I understand you correctly you want something like this concept:
example: http://buildyourownbagel.com/test/test.html test.html: Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Code:
<?php |
| All times are GMT +1. The time now is 04:29 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.