www.webdeveloper.com
Results 1 to 3 of 3

Thread: Setting hash of top document within ajax request

  1. #1
    Join Date
    Mar 2009
    Posts
    46

    Post Setting hash of top document within ajax request

    Hello, I am having trouble setting window.location.hash within a ajax request.

    This is what is in the ajax request:

    post.php
    Code:
    <?php
    if ($_POST['page'] == 1) {
    echo '<script type="text/javascript"> window.location.hash = "#page1"; </script>';
    
    		} else {
    		echo 'error'; 
    ?>
    This is the code that handles the request:
    Code:
       function makeRequest(url, parameters) {
    
          http_request = false;
          if (window.XMLHttpRequest) { // Mozilla, Safari,...
             http_request = new XMLHttpRequest();
             if (http_request.overrideMimeType) {
             	// set type accordingly to anticipated content type
                //http_request.overrideMimeType('text/xml');
                http_request.overrideMimeType('text/html');
             }
          } else if (window.ActiveXObject) { // IE
             try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
             } catch (e) {
                try {
                   http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
             }
          }
          if (!http_request) {
             alert('Cannot create XMLHTTP instance');
             return false;
          }
         http_request.onreadystatechange = alertContents;
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded", "text/javascript", "application/javascript");
          http_request.setRequestHeader("Content-length", parameters.length);
          http_request.setRequestHeader("Connection", "close");
          http_request.send(parameters);
    
       }
    It does not change the hash, i have tried document.location.hash as well. What gives?
    Last edited by yahooman123; 05-13-2010 at 02:05 PM.

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    What are the actual values of url and parameters being passed to the function?

  3. #3
    Join Date
    Mar 2009
    Posts
    46
    Got it to work by using eval function on the content between the script tags.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles