Results 1 to 3 of 3

Thread: Need some help with passing some commands into a function.

  1. #1
    Join Date
    Aug 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need some help with passing some commands into a function.

    Hello,

    I got this script that I coded up last night but for some reason whenever i passed stuff into the function, it comes up as 'undefined' I've had issues like this before but can't remember how i solved it the XMLHttpRequest object works but it relies on these inputs to perform the correct commands back to my PHP file that sends back the requested data.

    So example of how I'm passing the commands in:

    getAjax('getallmessages','inline_chat_win');

    the first command will be used to pass to the php file and the second is the DIV element to be used in:

    $(''+ div +'').html(httpReq.responseText).fadeIn(1000);

    But neither get the correct input as both just get undefined? This has baffled me as I've tried doing many things to solve it.... here's my function below:

    Code:
      function getAjax(cmd,frame) {
      var httpReq;
        
      try{ // Firefox, Opera 8.0+, Safari
      httpReq = new XMLHttpRequest();
      } catch (e) {
      try{ // Microsoft Internet Explorer (ActiveX)
      httpReq = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try{ // Again with Microsoft => Boring!
      httpReq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
      // Oh dear their browser doesn't support this? This is very rare!
      alert("Your browser seems to not support the XMLHttpRequest object? Please consider upgrading your browser.");
      return false;
      }
      }
      }
      
      httpReq.onreadystatechange = function() {
      // Remember to also set 200 for the status
      if( httpReq.readyState == 4 && httpReq.status == 200 ) {
      $('#'+ frame +'').html(httpReq.responseText).fadeIn(1000);
      }
      }
      var command = cmd;
      httpReq.open("GET","inline_chat.php?cmd_="+ command,true);
      httpReq.send(null);
      }
      
      window.onload = function() {
      setInterval("getAjax()",10000);
      }
    and heres the code block that sends in the input:

    Code:
      window.onload = function() {
      $("#loading").remove();
      getAjax('getallmsgs','inline_win_chat'); // Gets all messages from the server
      }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I see two window.onload:

    Code:
      window.onload = function() {
      setInterval("getAjax()",10000);
      }
    and:

    Code:
      window.onload = function() {
      $("#loading").remove();
      getAjax('getallmsgs','inline_win_chat'); // Gets all messages from the server
      }
    There can be only one on a page, and whichever is parsed last by the browser will be the one that's used. If that happens to be the one with no parameters passed to the function, those parameters will be undefined.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bennyy007 (10-19-2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you that did the trick i feel really stupid for making that mistake, again was tired when i did that part. But thanks again!!!

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
  •