Jquery POST unicode字符串到codeigniter php


Jquery POST unicode string to codeigniter php

我正在尝试使用jquery实现一个自定义建议引擎。

我接受用户输入,调用我的codeigniter v2 php代码,以便从预先构建的同义词表中获得匹配项。

我的javascript如下:

var user_str = $("#some-id").val();
$.ajax({
    type: "POST",
    url: "http://localhost/my-app/app/suggestions/",
    data: {"doc": user_str},
    processData: false
})
.done(function (data)
{
    // Show suggestions...
});

我的PHP代码(控制器)如下:

function suggestions()
{
    $user_input = trim($_POST['doc']);
    die("[$user_input]");
}

但数据并没有发布到我的PHP中:(作为echo,我得到的只是一个空的[](没有500错误或任何东西)

我花了两天时间寻找答案,我在SO/谷歌上读到的内容没有帮助。我可以使用GET实现这一点,但话说回来,这对unicode字符串不起作用,所以我想我应该使用POST(只是这也不起作用:()

有人能告诉我怎么解决这个问题吗?此外,这必须使用unicode字符串,这是该项目中的一个重要要求。

我使用的是PHP 5.3.8

尝试使用$.post方法,然后进行调试。这样做:

JS-

var user_str = $("#some-id").val();
var url = "http://localhost/my-app/app/suggestions";
var postdata = {doc:user_str};
$.post(url, postdata, function(result){
    console.log(result);
});

PHP

function suggestions(){
    $user_input = $this->input->post('doc');
    return "MESSAGE FROM CONTROLLER. USER INPUT: ".$user_input;
}

这应该会将消息输出到控制台。如果有效,请告诉我。

对于那些感兴趣的人来说,这对我来说很有效,即使csrf_protection设置为真正的

var cct = $.cookie('csrf_the_cookie_whatever_name');
$.ajax({
    url: the_url,
    type: 'POST',
    async: false,
    dataType: 'json',
    data: {'doc': user_str, 'csrf_test_your_name': cct}
})
.done(function(result) {
    console.log(result);
});