2

我从 CodeIgniter 收到此错误:

您提交的 URI 包含不允许的字符。...

在这个 JSON 字符串上:

{"from":"feedback@myapp.com","to":"support@myapp.com","cc":"myadmin@ myapp.com, myfellowadmin@myapp.com","subject":"FROM APP: User Feedback","message":"FROM USER: testy.testerson@testme.com:\nHere's a test comment"}

当我尝试使用以下方法对其进行编码时:

URLreadyJSON = encodeURIComponent(JSON.stringify(JsonObj));

JsonObj是上面提到的 JSON 字符串。)

URLreadyJSON解析为:

https://127.0.0.1/Xhr/email/%7B%22from%22%3A%22feedback%40myapp.com%22%2C%22to%22%3A%22support%40myapp.com%22%2C%22cc%22%3A%22myadmin%40myapp.com%2C%20myfellowadmin%40myapp.com%22%2C%22subject%22%3A%22FROM%20APP%3A%20User%20Feedback%22%2C%22message%22%3A%22FROM%20USER%3A%20testy.testerson%40testme.com%3A%5CnHere's%20a%20test%20comment%22%7D

相关代码:

function sendFeedback() {
    JsonObj = { 
        'from': 'feedback@myapp.com',
        'to': 'support@myapp.com',
        'cc': 'myadmin@myapp.com, myfellowadmin@myapp.com',
        'subject': 'FROM APP: User Feedback',
        'message': 'FROM USER: ' + $('#feedback_email').val() + ":\n" + $('#feedback_message').val()
    }

    URLreadyJSON = encodeURIComponent(JSON.stringify(JsonObj));

    $.ajax({
        url: "/Xhr/email/" + URLreadyJSON,
        type: 'POST',
        dataType: 'json',
        success: function(data) {
            $('#feedback_feedback').text(data.message);
            if(!data.error) {
                $("#feedback_popup").popup("open");   // Open confirm popup
                $('#feedback_message').text('');      // Clear original message input
                $('#feedback_email').text('');        // Clear sender email
                setTimeout(function() { $("#feedback_popup").popup("close") }, 2500);
            }
        },
        fail: function(data) {
            console.log("FAIL");
            console.log(data);
        }
    });
}

最后,在我的 CodeIgniter 配置文件中,我将allowed_uri_chars设置为:

$config['permitted_uri_chars'] = 'a-z 0-9~%.,":_?&=;}{@-';

我已经检查了我能找到的所有解决这个错误的解决方案(并且有一些),并结合了这些建议,但没有成功。我一定错过了什么,我希望有人能看到那是什么。

4

2 回答 2

3

尝试改变:-

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\=';

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\=+';
于 2017-12-07T12:00:02.227 回答
1
function sendFeedback() {
JsonObj = { 
    'from': 'feedback@myapp.com',
    'to': 'support@myapp.com',
    'cc': 'myadmin@myapp.com, myfellowadmin@myapp.com',
    'subject': 'FROM APP: User Feedback',
    'message': 'FROM USER: ' + $('#feedback_email').val() + ":\n" + $('#feedback_message').val()
}

$.ajax({
    url: "/Xhr/email/",
    type: 'POST',
    dataType: 'json',
    data : JsonObj, // add this
    success: function(data) {
        $('#feedback_feedback').text(data.message);
        if(!data.error) {
            $("#feedback_popup").popup("open");   // Open confirm popup
            $('#feedback_message').text('');      // Clear original message input
            $('#feedback_email').text('');        // Clear sender email
            setTimeout(function() { $("#feedback_popup").popup("close") }, 2500);
        }
    },
    fail: function(data) {
        console.log("FAIL");
        console.log(data);
    }
});

}

服务器端:

$from: $this->input->post('from',true);
$to: $this->input->post('to',true);
$cc: $this->input->post('cc',true);
$subject: $this->input->post('subject',true);
$message: $this->input->post('message',true);
于 2015-11-27T10:57:25.163 回答