Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am displaying a list of country in the drop down list, retrive it from the database . and i need to display price for the selected country based on the options chosen by the customers in the drop down list without that page getting refreshed.

the url i m passing in ajax is not calling the php file url: "cities.php",

is any one help me how to do that any suggestions.

i am use exec php plugin to write the php code in the page.

This is my code

                         <?php
 // Establish a database connection (adjust address, username, and password)

$con= mysqli_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());

mysql_select_db("geo_ip");

// Create a query string

$query = "SELECT countryFROM  geo_ip ";

    $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
   echo "<select name=myselect onChange='get_cities(this.value)'>";  

       while($row=mysql_fetch_array($result)){ 

           echo "<OPTION VALUE=".$row['country'].">".$row['country']."</OPTION>";
        }

          echo "</select>"; 

        echo "<select name='city' id='city'></select>"; //We have given id to this dropdown

           ?>
          <script>
          function get_cities(country)
        {
         $.ajax({
       type: "POST",
       url: "cities.php", /* The country id will be sent to this file */
       beforeSend: function () {
       $("#price").html("<option>Loading ...</option>");
    },
   data: "country="+country,
   success: function(msg){
     $("#price").html(msg);
   }
   });
    } 
   </script>
share|improve this question
cities are in a different database then the wordpress? – Sisir Apr 22 at 12:50
no same database – Raja Apr 22 at 12:54
1  
Why aren't you using WP core functions then? – t f Apr 22 at 12:55
i want to display value regarding to the selected value in the dropdown .can you provide me some examples – Raja Apr 22 at 13:07
I expect that the issue is with the relative url but you are doing this wrong in at least two other ways: 1) not using $wpdb, as already mentioned, and 2) not using the AJAX API – s_ha_dum Apr 22 at 14:01
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.