SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting "url is not valid and can not be loaded."

    I am having a problem with an AJAX/php form search I am trying to do. When it loads into Firefox, I get a messagbox that says "url is not valid and cannot be loaded". It ends up loading the page and it works fine however in IE it won't even load. I have gone over my code over and over again and can't seem to find anything that looks out of sorts to me.

    here is the javascript code (I'm guessing it is in here somewhere)

    Code:
    var xmlhttp;
    var xmlhttp2'';
    
    function showCat(str)
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var url="getuser.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    
    xmlhttp.open("GET",url,true);
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send(null);
    
    
    showTablecat(str);
    
    }
    
    function MsgBox(str){
    
    alert (str);
    
    } 
    
    function showTablecat(str)
    {
    
    xmlhttp2=GetXmlHttpObject();
    if (xmlhttp2==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var url="catsearch.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp2.onreadystatechange=resultstable;
    xmlhttp2.open("GET",url,true);
    xmlhttp2.send(null);
    
    }
    
    function showTable(str)
    {
    
    xmlhttp2=GetXmlHttpObject();
    if (xmlhttp2==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var url="showtable.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp2.onreadystatechange=resultstable;
    xmlhttp2.open("GET",url,true);
    xmlhttp2.send(null);
    
    }
    
    function resultstable()
    {
    if (xmlhttp2.readyState==4)
    {
    
    document.getElementById("displayresults").innerHTML=xmlhttp2.responseText;
    }
    }
    
    
    function stateChanged()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
    }
    
    
    
    function GetXmlHttpObject()
    {
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
      }
    if (window.ActiveXObject)
      {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
      }
    return null;
    }
    
    
    
    function showdesc(str)
    {
    
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    
    var url="getnumber.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp.open("GET",url,true);
    xmlhttp.onreadystatechange=stateChangeDesc;
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send(null);
    
    showTable(str);
    
    }
    
    function stateChangeDesc()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("number").innerHTML=xmlhttp.responseText;
    }
    }
    My index.php code is here:

    Code:
    <?php 
    include('header.php');
    include('dbconnect.php')
    ?>
    
    <h2>View/Search Available Inventory</h2>
    <div id = 'category' >
    <form>
    Select a Category:
    <select name="users" onchange="javascript:showCat(this.value)">
    <option selected value=''>--SELECT--</option>
    <?php
    
    $sql="SELECT * FROM categories";
    
    $result= mysql_query($sql);
    
    while ($row = mysql_fetch_array($result)){
    
    $cat = $row['category'];
    $num = $row['id'];
    
    echo "<option value='".$num."'>".$cat."</option>";
    }
    
    ?>
    
    </select>
    </div>
    <div id="txtHint">Select a description<select name="description" onchange="javascript:showdesc(this.value)">
    <?php
    
    
    $sql="SELECT Item_number, description FROM inventory order by description";
    
    $result= mysql_query($sql);
    
    echo "<option selected value=''>--SELECT--</option>";
    while ($row = mysql_fetch_array($result)){
    
    $desc = $row['description'];
    $itemnum =$row['Item_number'];
    
    echo "<option value='".$itemnum."'>".$desc."</option>";
    }
    mysql_close();
    
    ?>
    
    </select>
    </div>
    
    <div id='number' >Enter the Item Number: <input type = "text" onkeyup="javascript:showTable(this.value)" /></div>
    <div id='buttons' ><input type="button" value="Add to inventory"/><input type="button" value="remove from Inventory" /></div>
    
    <div id="displayresults">Results will appear here</div>
    </form>
    <?php include('footer.php');
    ?>
    </body>
    </html>
    everything seems to work fine in google Chrome, but forget about IE, it will not even keep the page loaded and safari has the same issues as firefox.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    First, please pass the javascript code through www.jslint.com and fix any issues that it reports.

    Second, use http://validator.w3.org/ to find problems with the HTML code and fix any issues reported there.

    If you have trouble understanding the reported issues, we will happily provide you with any assistance to help you understand how to resolve the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was some autogenerated code that my editor put in the <head> section, the one time I was too lazy to input the meta data by hand..... Thanks for the links though, I knew about the w3 validator but the jslint is a handy thing.


Bookmarks

Posting Permissions

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