1
我想在PHP中使用AngularJS和Arrest REST API做一個簡單的CRUD應用程序作爲後端。
GET和DELETE正常工作。但是PUT和POST會給我帶來麻煩。我需要提供的數據不是以JSON格式,而是以更基本的格式(我不想在Arrest API中進行太多挖掘)。
我試着用PUT和POST工作,用jQuery完成一個簡單的測試,我得到以下網絡活動。這裏顯示的POST工作正常。
`Request URL:http://anyhost.com:8888/angular18/api/allIP
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:43
Content-Type:application/x-www-form-urlencoded
Host:anyhost.com:8888
Origin:http://anyhost.com:8888
Referer:http://anyhost.com:8888/angular18/api/api-test.html
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
name:mynewxxx
provider:xxx
technology:28xxx
Response Headersview source
Connection:Keep-Alive
Content-Length:44
Content-Type:application/json
Date:Fri, 19 Jul 2013 19:45:46 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8x DAV/2 PHP/5.3.6
X-Powered-By:PHP/5.3.6`
現在,我做這個用的AngularJS作爲工廠下面的代碼
TodoApp.factory('Todo', function($resource) {
return $resource('api/allIP/:id', {id:'@id'}, {update:{method: 'PUT'}});
});
我得到的網絡活動POST像下面時,實際插入到數據庫中是行不通的。 我想我應該能夠強制AngularJS以不同的方式編碼負載,但我不知道如何做到這一點。 如果有人能幫助我將是巨大的 感謝 彼得
BTW:我改變所有本地主機信息,以anyhost.com在這個問題上的條目,因爲它是不允許我繼續本地主機
`Request URL:http://anyhost.com:8888/angular18/api/allIP
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:50
Content-Type:application/json;charset=UTF-8
Host:anyhost.com:8888
Origin:http://anyhost.com:8888
Referer:http://anyhost.com:8888/angular18/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payloadview parsed
{"name":"xxx","provider":"xxx","technology":"xxx"}
Response Headersview source
Connection:Keep-Alive
Content-Length:45
Content-Type:application/json
Date:Sat, 20 Jul 2013 07:09:29 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8x DAV/2 PHP/5.3.6
X-Powered-By:PHP/5.3.
`