How to return result from ajax call synchronously?

Javascript not working on ajax loaded page?

  • i have a page of the form <script src="script.js" .. /> <script src="ajax.js" .. /> <select...><option....></select> <div> //loaded from file.php by getElement() </div> //script.js function fun() { ... } //ajax.js function getXMLHTTP() { //function to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getElement(strURL,divElement) { document.getElementById(divElement).in… var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById(divElement).i… } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } //file.php -- loaded page //some text here <script> fun(); </script> //some text here the main problem that i am facing is i have a function call on the ajax loaded page . None of the other site tell how to handle this situation, they only give scripts for parsing the loaded file for script tags and adding to head.. Can someone please help me out as soon as possible (without jQuery)....

  • Answer:

    Very confusing question however I guess you have something to do with //file.php -- loaded page This part has an included script which will be executed whenever this script gives output (prints page). It is because you are calling a function inside script tag. May be you could explain little more that what you want to do? and what is the behavior and how its different than requirement etc =)

george at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.