简体   繁体   English

Codeigniter REST API发布不起作用

[英]Codeigniter REST API post not working

require APPPATH.'libraries/REST_Controller.php';

class Test extends REST_Controller {

function ajax_all_webinars_get() {
    $this->response(array("success"=>"get"), 200);
}

function list_post() {
    $this->response(array("success"=>"post"), 200);
}
}

In the browser I can make a call to ajax_all_webinars via a javascript ajax call to retrieve all the webinars and get a 200 OK. 在浏览器中,我可以通过javascript ajax调用来调用ajax_all_webinars,以检索所有网络研讨会并获得200 OK。

However when I even try to post to the post function I get a 404. 但是,当我什至尝试发布到post函数时,我都会得到404。

can anyone help please. 谁能帮忙。

call to the service 致电服务

$.ajax({
type: "post",
url: "http://corss-domain-server/test/list/",
crossDomain: true,
data: postData,
//dataType: "json",
success: function(responseData, textStatus, jqXHR) {
    console.log(responseData)
},
error: function(jqXHR, textStatus, errorThrown) {
    console.log(jqXHR);
}
})

The main reason that codeigniter doesn't recognize the post data in REST Api is not setting content-type . Codeigniter无法识别REST Api中的发布数据的主要原因不是设置content-type

So Set the content-type in Ajax Call and check. 因此,在Ajax Call中设置内容类型并进行检查。

You can add the below line to the ajax call,if below line not works then try any other content type. 您可以将以下行添加到ajax调用中,如果以下行不起作用,请尝试其他任何内容类型。

contentType: "application/x-www-form-urlencoded" contentType:“应用程序/ x-www-form-urlencoded”

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

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