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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I cannot get Countries loaded into the Country DropDown List.

    $(document).ready(function(){
    var COUNTRYCOD = 0;
    $.ajax({
    type : "POST",
    url : "http://localhost/ajaxphpmysql/GETCOUNTRIES.PHP",
    dataType : "json",
    success : function(COUNTRY){
    var CBOCONTROL = $("#COUNTRYCBO");
    CBOCONTROL.empty();
    for ( N = 0; N < COUNTRY.length;N++){
    CBOCONTROL.Append("<OPTION VALUE=" + COUNTRY[N].COUNTRYCOD + ">" + COUNTRY[N].COUNTRYNAM + "</OPTION>");
    };
    }
    });
    });


    ##############################################################
    ##############################################################
    GETCOUNTRIES.PHP


    <?php

    $CON = mysql_connect("localhost","root","");
    mysql_select_db ( "AJAXDBF", $CON );
    $SQLCOUNTRY = " SELECT * FROM COUNTRY ";
    $FCOUNTRY = mysql_query( $SQLCOUNTRY , $CON);
    $COUNTRIES = array();
    while ( $ROW = mysql_fetch_array( $FCOUNTRY )){
    $ROW_ARRAY = array(
    'COUNTRYCOD' => $ROW["COUNTRYCOD"],
    'COUNTRYNAM' => $ROW["COUNTRYNAM"]
    );
    array_push($COUNTRIES, $ROW_ARRAY);
    }
    echo ( json_encode($COUNTRIES ));

    ?>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    You should run your PHP script and check if the output is what you think it is.

    As far as the ajax script: I believe that the success : function() is no longer used;
    Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
    The done (function(){}) is used instead.
    No Guarantee but this might work
    PHP Code:
    <script type="text/javascript">
    $(
    document).ready(function(){
        var 
    COUNTRYCOD 0;
        $.
    ajax({
        
    type "POST",
        
    url "ajax.PHP",
        
    dataType "json",
        })
        .
    done (function(COUNTRY){
        var 
    CBOCONTROL = $("#COUNTRYCBO");
        
    CBOCONTROL.empty();
        for ( 
    0COUNTRY.length;N++){
            
    CBOCONTROL.Append("<OPTION VALUE=" COUNTRY[N].COUNTRYCOD ">" COUNTRY[N].COUNTRYNAM "</OPTION>");
        };
        });
    });
    </script> 
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by sunfighter View Post
    As far as the ajax script: I believe that the success : function() is no longer used;

    Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
    I think that's only referring to the Promise methods:
    Code:
    $.ajax("example.php")
        .success(function() {
            alert( "success" );
        })
        .error(function() {
            alert( "error" );
        })
        .complete(function() {
            alert( "complete" );
        });
    not to the ajax callback option:
    Code:
    $.ajax({
       url: "example.php",
       success: function() {
           alert( "success" );
       },
       error: function() {
           alert( "error" );
       },
       complete: function() {
           alert( "complete" );
       }
    });


  •  

    Posting Permissions

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