jQuery Ajax with POST to send string doesn't work

I have already seen all the q&a here, and I couldn't fix the problem. I'm trying to send a two character string.

var country_code = 'PT';
  $.ajax({
    url: 'GetData.php',
    type: 'POST',
    data: {'country': country_code},
    dataType: "json",
    success: function(res) {
      ...
    },
    error: function () {                    
      console.log("There was an error");
  }
});

on GetData.php I just have

$cty = $_POST['country'];

$query = "SELECT DISTINCT uuid_client, country FROM users_insertions WHERE country='".$cty."'";
...
echo json_encode($res); 

Though, it doesn’t work. I can't get the string on GetData.php What am I doing wrong?

Upvotes: 0

Views: 230

Answers (2)

I found my problem. It was the Apache .htaccess file that was changing the URL to something else. If nothing else works, try checking your .htaccess file.

Upvotes: 0

hamed
hamed

Reputation: 8043

Your code does not have any serious problem, but I think It's better to use data: {country: country_code} instead of data: {'country': country_code}. Maybe this can solve your problem.

Upvotes: 1

Related Questions