简体   繁体   中英

How to get ajax request in php?

    $.ajax({
        type: "POST",
        url: "Check_Country.php",
        data: "{Country_name: "+Country_name+"}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(html){
            $('select#Section').empty();
            $('select#Section').append('<option>Select</option>');
            $('select#Section').append(html);
        }
    });

How do you detect Country_name in Check_Country.php file? I am using

$_POST['Country_name']; 

in php file but, the console says that it cannot find Country_name .

Try to use

data: "{Country_name: "+Country_name"}"

instead of

data: "{Country_name: "+Country_name+"}"

ie remove the trailing + sign.

In your code only one syntax is wrong you have to change this code :-

data: "{Country_name: "+Country_name+"}",

into

data: {"Country_name": Country_name}
or 
data:   "Country_name="+Country_name,

please try this:-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM