I want to do a simple CRUD application with AngularJS and Arrest REST API in PHP as backend.
GET and DELETE are working just fine. But PUT and POST gives me troubles. I need to give the data not in JSON but in a more basic format (I don't want to dig too much into the Arrest API).
I tried out to have PUT and POST work with a simple test done with jQuery and I get the following network activity. The POST shown here is working fine.
`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`
Now, when I do this with the AngularJS using as a factory the following code
TodoApp.factory('Todo', function($resource) {
return $resource('api/allIP/:id', {id:'@id'}, {update:{method: 'PUT'}});
});
I get the network activity for POST like below, the actual insert into the database is not working. I think I should be able to force AngularJS to code the payload differently, but I don't know how to do this. If somebody could help me would be great thanks Peter
BTW: I change all localhost info to anyhost.com on this question entry as it was not permitting me to keep localhost
`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.
`