Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter-restserver does not accept POST method CORS
    primarykey
    data
    text
    <p>I'm developing a REST API using <strong>Codeigniter-restserver</strong> for a mobile applications in <strong>Phonegap</strong>.</p> <p>Since <strong>Phonegap</strong> loads <code>index.html</code> using <code>file://</code>, my API should support <strong>CORS</strong>. And I'm new to this <strong>CORS</strong>.</p> <p>I've set headers in <code>libraries/REST_Controller.php</code></p> <pre><code>header("Access-Control-Allow-Origin: *"); header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept'); </code></pre> <p>And I'm using <strong>Backbone.js</strong>.</p> <p>Here is my Controller</p> <p> <pre><code>// This can be removed if you use __autoload() in config.php OR use Modular Extensions require APPPATH.'/libraries/REST_Controller.php'; class Prop extends REST_Controller { public function __construct() { parent::__construct(); $this-&gt;load-&gt;database(); } function property_get() { ... } function property_post() { ... } function attach_image($file_type) { if($this-&gt;post($file_type) != ""){ save_base64_image($file_type,$this-&gt;post($file_type)); $this-&gt;email-&gt;attach($_SESSION[$file_type]); } } function property_delete() { ... } function share_post() { $email_id = $this-&gt;post('emailid'); $config['mailtype'] = "html"; $this-&gt;email-&gt;initialize($config); $this-&gt;email-&gt;from('myid@gmail.com', 'mobile app'); $this-&gt;email-&gt;to($email_id); $this-&gt;email-&gt;subject('subject'); $this-&gt;email-&gt;message('message'); if ( ! $this-&gt;email-&gt;send() ) { $this-&gt;response("Internal server error.", 500); } else { $result = new stdClass(); $result-&gt;message = 'Email has been sent.'; $this-&gt;response($result, 200); // 200 being the HTTP response code } } public function send_post() { var_dump($this-&gt;request-&gt;body); } public function send_put() { var_dump($this-&gt;put('foo')); } </code></pre> <p>}</p> <p>Here's my jQuery ajax call.</p> <pre><code>$.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)); }); </code></pre> <p>I'm able to access this <code>/share/format/json</code> API with POSTMAN, chrome extension, but not with <code>file://</code> or <code>localhost://</code>.</p> <p><strong>EDIT:</strong></p> <p>I've also tried changing <code>share_post()</code> to <code>share_gett()</code>, It worked. But i need it in POST.</p> <p>I'm stuck on this for the past 48 hours. Tried many solutions, but nothing helped me with this issue. Please help me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload