Codeigniter restserver不接受POST方法CORS

Codeigniter restserver不接受POST方法CORS,rest,backbone.js,cordova,cors,codeigniter-restserver,Rest,Backbone.js,Cordova,Cors,Codeigniter Restserver,我正在为Phonegap中的移动应用程序使用Codeigniter restserver开发一个restapi 由于Phonegap使用file://加载index.html,我的API应该支持CORS。我是新来的CORS 我已经在libraries/REST\u Controller.php header("Access-Control-Allow-Origin: *"); header('Access-Control-Allow-Headers:Origin, X-Requested-Wit

我正在为Phonegap中的移动应用程序使用Codeigniter restserver开发一个restapi

由于Phonegap使用
file://
加载
index.html
,我的API应该支持CORS。我是新来的CORS

我已经在
libraries/REST\u Controller.php

header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept');
我使用的是主干.js

这是我的控制器

}

这是我的jQuery ajax调用

$.ajax( {
        url: PMSApp.apiUrl + "/share/format/json",
        type: 'post',
        dataType: "json",
        contentType: "application/json; charset=utf-8"
    })
    .done(function(response) {
        console.log(JSON.stringify(response));
})
.fail(function(response) {
        console.log(JSON.stringify(response));
})
.always(function(response) {
        console.log(JSON.stringify(response));
}); 
我可以使用POSTMAN、chrome扩展名访问此
/share/format/json
API,但不能使用
文件://
本地主机://

编辑:

我还尝试将
share\u post()
更改为
share\u gett()
,效果不错。但我需要邮寄


在过去的48个小时里,我一直在做这件事。尝试了许多解决方案,但在这个问题上没有任何帮助。请帮助我。

您必须使用访问控制允许源代码启动Chrome

此线程:

检查此踏板:
Phonegap提供了将您的Web服务域列入白名单的选项。它是在配置xml中设置访问源的

你好,谢谢你的回复。实际上我正在开发一个Phonegap应用程序。所以我无法在那里设置此选项。我经常为Phonegap应用程序设置此选项。只是别忘了编辑config.xml哦,我不知道Phonegap中有这样的选项。我就用那种方式试试。谢谢巴特:)你是怎么解决的?@Leandro phonegap有一个功能可以列出你的域名。它需要在config.xml中设置
$.ajax( {
        url: PMSApp.apiUrl + "/share/format/json",
        type: 'post',
        dataType: "json",
        contentType: "application/json; charset=utf-8"
    })
    .done(function(response) {
        console.log(JSON.stringify(response));
})
.fail(function(response) {
        console.log(JSON.stringify(response));
})
.always(function(response) {
        console.log(JSON.stringify(response));
});