[請益] codeigniter 中使用XMLHttpRequest發送po

看板PHP作者 (raison detre)時間12年前 (2013/06/13 16:35), 編輯推噓0(0010)
留言10則, 3人參與, 最新討論串1/1
請問一下 我使用 XMLHttpRequest 向 codeigniter 發送一個post要求 並且代入 json={"name":"user"} 但是我在server端使用 echo $this->input->post('json'); 取不到值 我用fiddler觀察送出去的資料 資料是有被夾帶進去的 唯一有差別的是他http協定中的content-type是 application/xml 但是我在javascript中去設定 XMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 瀏覽器在執行的時候會跟我報錯 ( DOM exception 11 ) 我用的是 Chrome 請問這該如何處理 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.220.71.34

06/13 18:51, , 1F
用file_get_contents("php://input")可以取得原來的值
06/13 18:51, 1F

06/14 09:04, , 2F
抱歉 ...我不是很懂,file_get_contents不是從檔案取值嗎
06/14 09:04, 2F

06/14 09:05, , 3F
為何可以取到http傳送的東西
06/14 09:05, 3F

06/14 09:11, , 4F

06/14 11:54, , 5F
我了解了,謝謝你們
06/14 11:54, 5F

06/14 11:54, , 6F
另外想請問是否只能使用這種方式
06/14 11:54, 6F

06/14 11:55, , 7F
還是codeigniter中有其他的處理方式
06/14 11:55, 7F

06/14 11:55, , 8F
然後codeigniter抓不出來是否真的與content-type有關係
06/14 11:55, 8F

06/14 22:33, , 10F
也可以直接使用這個啦
06/14 22:33, 10F
文章代碼(AID): #1HkOHPDY (PHP)
文章代碼(AID): #1HkOHPDY (PHP)