繁体   English   中英

带有 POST 的 jQuery Ajax 发送字符串不起作用

[英]jQuery Ajax with POST to send string doesn't work

我已经看到这里的所有问答,我无法解决问题。 我正在尝试发送一个两个字符的字符串。

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");
  }
});

在 GetData.php 上我只有

$cty = $_POST['country'];

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

虽然,它不起作用。 我无法在 GetData.php 上获取字符串我做错了什么?

您的代码没有任何严重问题,但我认为最好使用data: {country: country_code}而不是data: {'country': country_code} 也许这可以解决您的问题。

我发现了我的问题。 Apache .htaccess 文件将 URL 更改为其他内容。 如果没有其他效果,请尝试检查您的 .htaccess 文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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