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.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trying to send URL values to .php file.

    Problem: I have a javascript onClick that runs a .php file behind the scenes using ajax xmlhttp.open. My php file doesn't see the values stored in the URL where the onClick link exists.

    Question: How do I send URL values so my .php file can update mysql database with those values?

    Code:
    
    My url looks like: index.php?id=1&test=hello
    My javascript:
    
    <script type="text/javascript">
    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
    
        }
      }
    xmlhttp.open("GET","bar_next.php",false);
    xmlhttp.send();
    }
    </script>
    
    
    
    
    
    My bar_next.php File
    
    
    
    <?php
    mysql_query("UPDATE members SET visited = CONCAT($_GET['id'],visited)
    WHERE username = '$_COOKIE[user]'");
    
    ?>

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    If you send the ajax request as a GET then you need to append any paramaters to the url ajaxPbj.open(). If you want to send the request as a POST then you send the parameters in the ajaxObj.send() plus you would need to add a few extra lines of code.

    AJAX tutorial

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    What would the coding look like? If you have the time...

  • #4
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    The tutorial on the other side of the link I posted gives example code.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by mxbikerider View Post
    What would the coding look like? If you have the time...
    try this:

    http://www.xul.fr/en-xml-ajax.html#ajax-post

    http://www.xul.fr/en-xml-ajax.html

    best regards


  •  

    Posting Permissions

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