我试图通过AJAX使用JavaScript从jQuery发送一个可能包含一个或多个URL的字符串。
该文本将由CodeIgniter控制器接收。
我出了点差错。有时是404错误,有时则是406错误,这取决于我发送数据的方式。
现在我就这样发过来:
var dsPost = encodeURIComponent(base64_encode(postContent));
$.ajax({
url: "/posts/createTextPost/" + dsPost,
type: "POST",
data: "userIdWall" + "=" + userIdWall,
success: function(data, textStatus, jqXHR) {
},
error: function (jqXHR, textStatus, errorThrown) {
}
});base64_encode fn是phpjs实现。
在CI控制器中,我这样做:
public function createTextPost($dsPost) {
$dsPost = base64_decode(urldecode($dsPost));
}问题是,数据可以保存到数据库,但我不明白为什么会出现404错误。
有什么想法吗?
谢谢。
发布于 2014-08-21 03:09:54
所以,谢谢你的想法,但答案可以在这里找到:
PHP/Apache Error:406 Not Acceptable
我引述有关的答覆:
如果任何用户输入项都以http://或https://开头,则网站将生成错误。 当我尝试使用以http://开头的链接时,我得到了一个406不可接受的链接: http://onkore.us/?blah=http://www.google.com 当我试着这样做的时候是可以的: http://onkore.us/?blah=www.google.com
发布于 2014-08-20 05:40:19
我建议在AJAX调用中将dsPost添加到数据中,而不是将其作为参数添加到url中:
$.ajax({
url: "/posts/createTextPost/",
type: "POST",
data: { "dsPost": dsPost, "userIdWall", userIdWall },
success: function(data, textStatus, jqXHR) {
// Yippie!
},
error: function (jqXHR, textStatus, errorThrown) {
// Bhuhuhu....
}
});然后,...and更新CI控制器以使用posted对象而不是输入参数:
public function createTextPost() {
$dsPost = base64_decode( urldecode( $this->input->post('dsPost') ) );
userIdWall = $this->input->post('userIdWall');
}发布于 2014-08-20 05:56:09
您必须通过ajax数据发送内容,如下所示。
$.ajax({
//double check your url setting in this way in case you have diffrent setting for index.php then remove the index.php
url: "<?=base_url()?>.index.php/posts/createTextPost/",
type: "POST",
data: {
"dsPost": dsPost,
"userIdWall", userIdWall
},
success: function(data, textStatus, jqXHR) {
},
error: function (jqXHR, textStatus, errorThrown) {
}
});然后在你的控制器里
public function createTextPost() {
$dsPost = base64_decode( urldecode( $this->input->post('dsPost') ) );
$userIdWall=$this->input->post('userIdWall');我希望这会有所帮助。
https://stackoverflow.com/questions/25397195
复制相似问题