Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AJAX and external scripts

    I have an AJAX call onChange of a select box.

    I'm, via the 'get' method, submitting to a php page and returning the results in a <div id='thediv'></div>

    The problem is - outside of the script I'm retrieving - are some scripts that run some navigation and other things of which one is an event handler.

    The problem is that AFTER I make the AJAX request, the event handler no longer functions. (the event handler is handling a menu)...

    How can I 'refresh' or 're-load' or whatever the external jscripts that have nothing to do with the AJAX script?

    MANY thanks in helping me solve this!

    My AJAX is simply the below:

    Code:
    function createQCObject() { 
       var req; 
       if(window.XMLHttpRequest){ 
          // Firefox, Safari, Opera... 
          req = new XMLHttpRequest(); 
       } else if(window.ActiveXObject) { 
          // Internet Explorer 5+ 
          req = new ActiveXObject("Microsoft.XMLHTTP"); 
       } else { 
          alert('Problem creating the XMLHttpRequest object'); 
       } 
       return req; 
    } 
    
    // Make the XMLHttpRequest object 
    var http = createQCObject(); 
    function displayDiv(path) {
    		
    	var ran_no=(Math.round((Math.random()*9999))); 
    	http.open('get', path);
       	http.onreadystatechange = function() {
    		if(http.readyState == 4 && http.status == 200) { 
    			checkForJavascript(http.responseText);
          		var response = http.responseText;
          		if(response) { 
          			document.getElementById("newsDiv").innerHTML = http.responseText; 
          		} 
       		} 
    	} 
    	http.send(null); 
    }
    Rich S. Wyatt
    D3 Web Creations

  • #2
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    When you wrote: "the event handler no longer functions," did you mean that the next time you select an item from the select list, the AJAX call is not made?

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ancora View Post
    Rich:

    When you wrote: "the event handler no longer functions," did you mean that the next time you select an item from the select list, the AJAX call is not made?
    Mike:

    No - sorry for the confusion.

    The select button still works great. The problem is with any external scripts that handle other parts of the page.

    To give more insight into what is going on:

    I have a left navigation being handled by an external .js.

    In the index.php I am including a module to handle the page. In that php exists the AJAX function referenced above. When the function is called it retrieves itself via the function with the appropriate 'get' variables.

    That part works great. It reloads and the appropriate content is shown.

    The problem, however, is that after I make a selection, and the AJAX call is made, the left nav no longer functions (for example - on hover it does hover but then does not "un-hover" after mouse-out)...

    So - I'm guessing that event handler is no longer being recognized by IE7 once I make the AJAX call. (by the way - this functions fine in FireFox 2, Opera and IE6)... Very weird.
    Rich S. Wyatt
    D3 Web Creations

  • #4
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    Yes, sorry for the confusion. I'm afraid I still don't understand. But, your AJAX code is a bit, "different" from what I use. Things seem to be out of order, and believe it or not the "get" is supposed to be uppercase and the "true" is missing from the open call.

    Just for the heck of it, try using my pro-forma AJAX code:

    Code:
    	var AdminResponse = "";
    
    	function parseSettings(){
    
    		alert(AdminResponse);
    		//**** Your parsing code here ****
    	}
    
    	function obtainSettings(){
    
    		var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
    		AdminRequest.onreadystatechange = function()
    			{
    		 	 if (AdminRequest.readyState == 4)
    				{
    		 	 	 if (AdminRequest.status == 200)
    					{
    			 	 	 AdminResponse = AdminRequest.responseXML;
    			 	 	 parseSettings();
    					}
    		 	 	 else 	{
    				 	 alert('Error Admin.xml File '+ AdminRequest.statusText);
    					}
    				}
    			}
    		var forceGET = "?n="+ parseInt(Math.random()*999999999);
    		AdminRequest.open("GET", "Admin.xml"+forceGET, true);
    		AdminRequest.send(null); 
    	}
    Making an AJAX call should have no effect on an external .js file. None. So, try it with the above code and see if that fixes it.

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Mike,

    I tried your script.. I like it better, very nice. :-)

    HOWEVER, still - after the call is made, I'm still unable to get the left nav to work properly. It still hangs as though it isn't catching window events anymore. Hmmm.
    Rich S. Wyatt
    D3 Web Creations

  • #6
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think I may have found a problem... I'm making the AJAX call within an include file in PHP... Here is how it is laid out:

    index.php (includes header.php) and if $_GET var matches then include the module (news.inc.php)...

    news.inc.php contains the AJAX code. The PATH that is being referenced and fetch happens to also be news.inc.php... Perhaps I need to move the AJAX stuff back to index.php and NOT include news.inc.php in the index, instead, call it via AJAX and have the results display in the DIV...

    Do you suppose that is where I went wrong?
    Rich S. Wyatt
    D3 Web Creations

  • #7
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    I think that there must be an ID or name that is conflicting, and the trouble doesn't happen until an ID or name is called somewhere in your AJAX code.

    I'd search the document and make a list of all IDs and all names. And then do the same for that external menu script. I'll bet that you'll find a conflict.

    This is very strange. If all your .php file is doing is echoing some text to be displayed in a div on the page, that couldn't be more innocuous.

  • #8
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    I just saw your post. I wouldn't include the AJAX code in index.php. I don't think you are supposed to call the calling page. I'd move that to a separate .php file.

  • #9
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    Why not just call the news.php file with the JavaScript AJAX code? Why worry about checking for $_GET or anything else. Call the .php file that delivers the news.

  • #10
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ancora View Post
    Rich:

    Why not just call the news.php file with the JavaScript AJAX code? Why worry about checking for $_GET or anything else. Call the .php file that delivers the news.
    That is what I've decided to do.

    I've included the AJAX in the index.php... The select box is now located there.
    onChange for the select box calls your AJAX function which calls the news.inc.php for news display.

    I've completely changed the name of the displaying div and I still get problems in IE7... what is the matter with this dumb browser? IE7 is the only one that hangs after the AJAX function gets called.
    Rich S. Wyatt
    D3 Web Creations

  • #11
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    You know what? I'd create another document without the menu, and test it. Also, I'd put a copy of the news.php file in the same directory as this simple test file. Just a plain, simple php document with the select list, the div, and AJAX code, and have it call the news.php, with both files in the same folder.

    I'll bet the problem disappears.

  • #12
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ancora View Post
    Rich:

    You know what? I'd create another document without the menu, and test it. Also, I'd put a copy of the news.php file in the same directory as this simple test file. Just a plain, simple php document with the select list, the div, and AJAX code, and have it call the news.php, with both files in the same folder.

    I'll bet the problem disappears.
    I think I miscommunicated again...

    The problem is not that the whole page hangs... I get the results I'm looking for in the display div. The problem is that after I make a change in the SELECT box and then get the correct output - my left nav no longer works properly.
    Rich S. Wyatt
    D3 Web Creations

  • #13
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    I understand, but what troubles me is that I don't think this news.php file should EVER be an include. There's just no reason for that. I'll bet that you have it in the "include" folder, the one specified by phpInfo(). I think that if you test a "clean" page, no paths, no includes, and rename the testing news file to news.php, that the problem will disappear.

    Heck, you might just try putting a copy of news.php in the root directory. Change the name of the copy to that, news.php and get rid of the news.inc.php.

    I think that calling a file in the "include" folder, just might be causing IE7 to scratch its head.

  • #14
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right - ok.

    I think I see what you're saying.

    In index.php I've dropped the include(/modules/news.inc.php) however the AJAX is calling the path ('/modules/news.inc.php?myvar=blah')

    Ok - so I tried what you said. I threw it all into one page.. No dice. This left nav still has a fit.

    I think it is in relationship to the sfmenu.js file which is handling the left navigation... I think it is pooping out after I do the ajax.
    Rich S. Wyatt
    D3 Web Creations

  • #15
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rich:

    Okay. I understand that this happens in IE7 only, but test your clean page with Firefox. First clear the JavaScript console before you load the clean page.

    And just for the heck of it, see if Firefox is reporting some "warnings" if not an actual error.

    The JavaScript console is under "Tools" on the menu bar.

    Sometimes it will report a warning that it doesn't consider to be an error, yet, IE7 might just be treating it as an error.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •