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 2014
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    $_GET not being set by Jquery autocomplete

    I am totally confused on this, what would cause $_GET to not set for Jquery's autocomplete?

    HTML:
    Code:
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script type="text/javascript" src="../templates/js/references_onloads.js"></script>
    . . .
    <div class="ui-widget">
        <form action="../ref_test.php" method="POST">
         <input type="text" id="topic" name="topic" value="" placeholder="TOPIC"><input type="submit" class="button" value="Submit" />
         <input type="hidden" id="indx" name="indx" value="" />
        </form>
    </div>
    jQuery:
    Code:
     $(function(){
      $('#topic').autocomplete({
       source:'../ref_test.php',
       minLength:2,
       autoFocus:true,
       select:function(event,ui){
        $('#topic').val(ui.item.label); // Display the selected text.
        $('#indx').val(ui.item.value); // Keep the selected id to hidden input.
        return false;
       }
      });
     });
    PHP:
    Code:
    if(isset($_GET['topic'])){
     $term = $_GET['topic'];
    }else{
     $term="GET NOT SET...";
    }
    
    [...just code to locate a match...]
    
    echo json_encode($result);
    Last edited by Trivius; Dec 14th, 2018 at 03:09 PM.

  2. #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    4,259
    Thanks
    3
    Thanked 553 Times in 538 Posts
    The submitted data will be in $_GET['term']. From the documentation -

    String: When a string is used, the Autocomplete plugin expects that string to point to a URL resource that will return JSON data. It can be on the same host or on a different one (must support CORS). The Autocomplete plugin does not filter the results, instead a query string is added with a term field, which the server-side script should use for filtering the results. For example, if the source option is set to "http://example.com" and the user types foo, a GET request would be made to Example Domainterm=foo. The data itself can be in the same format as the local data described above.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

  3. #3
    New Coder
    Join Date
    Oct 2014
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Omg, you have to use 'term', I had no idea, though it was supposed to be the name of the input in the form. I just tried it and it works. You're a genius! Thanks for that.

  4. #4
    New to the CF scene
    Join Date
    Feb 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much Trivius, Can you tell, Do you have any video resource for learn easily ajax ?

  5. #5
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,996
    Thanks
    36
    Thanked 1,072 Times in 1,068 Posts
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


 

Tags for this Thread

Posting Permissions

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