algorithmicCoder
algorithmicCoder

Reputation: 6789

Why does this JQuery/AJAX call not work?

Trying to implement an autocomplete box ultimately. For now im following php academy's lead. I just want to echo out "suggestions go here" underneath the input area when anything is entered. I have to files. home.php and country.php. home contains the input part and country.php just prints the dummy suggestion text. Right now when I type in the input area ..nothing happens. I am using jquery v 1.6.2 (jquery-1.6.2.min.js)

home.php is:

<html>
 <head>
  <script type ="text/javascript" src ="jquery.js"></script>
   <script type ="text/javascript">
    function getSuggestions(value){
     #.post("country.php", {countryPart:value}, function(data){
        $("#suggestions").html(data);
      });

    }
   </script>

 </head>

 <body>
    <div id = "content_holder">
       <input type = "text" name="country" value= "" id = "country" onkeyup="getSuggestions(this.value);" />
       <div id ="suggestions"></div>
    </div>
  </body>
</html>

country.php is

<?php

echo "Suggestions Go Here";


?>

Upvotes: -1

Views: 154

Answers (7)

The Mask
The Mask

Reputation: 17427

The method name should be $ not #

you can use the "console of error"(ctrl + shift + j in monzilla firefox) for check error in javascript/HTML execution

Upvotes: -1

devtut
devtut

Reputation: 697

You can use like below code.

$.ajax({
   type: "POST",
   url: "country.php",
   data: "name=value",
   success: function(data){
     $("#suggestions").html(data);
   }
 });

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69905

It should be $.post and #.post

Upvotes: -1

slandau
slandau

Reputation: 24052

If you're truly using JQuery, you need to change your post call to this:

$.post("country.php", {countryPart:value}, function(data){
    $("#suggestions").html(data);
});

You had # instead of $ before the post call.

Upvotes: -1

Esben
Esben

Reputation: 1971

you wrote

#.post

should be

$.post

try that :)

Upvotes: 1

genesis
genesis

Reputation: 50966

$.post

not

#.post

it will work.

if you're working with jquery

$.post("country.php", {countryPart:value}, function(data){
        $("#suggestions").html(data);
});

Upvotes: 1

JFFF
JFFF

Reputation: 989

Never seen #.post before... try using $.post

Upvotes: 3

Related Questions