KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm using AJAX on a knockout.js form to post some information that CakePHP should receive, however, Cake doesn't seem to find anything. Also, the alert isn't appearing despite a 200 status (OK) from the POST. Here's the AJAX $.ajax({ url: "/orders/finalize_payment", type: "POST", dataType: "json", contentType: "json", data: JSON.stringify({"customer": customer_id}), success: function(){ alert("success"); } }); Here's the corresponding action in the orders controller. Right now, I completely stripped it to just the bare minimum. function finalize_payment($id = null){ $this->layout = false; $this->autoRender = false; if($this->request->is('post')){ //the user has submitted which status to view print_r($this->request->data); echo "test"; //just to make sure it's reaching this point } } When I open up the network tab in chrome, it shows the request payload as customer: 1 The POST shows as success, status 200. I checked the response headers and it just shows array ( ) test Despite chrome showing a payload being sent, CakePHP isn't finding it apparently. Update I changed the request from AJAX to $.post and it worked. I still have no clue why $.post("/orders/finalize_payment",{"customer_id":customer_id},function(data){ alert('success'); });
Tags (comma-separated)
Save Edits
Cancel