Mysql 如何在angularjs的restful api中传递数据

Mysql 如何在angularjs的restful api中传递数据,mysql,angularjs,rest,Mysql,Angularjs,Rest,我想在mysql表中添加一个新条目。我从一个高级restful客户端测试了API。很好用 但当我尝试使用angular js时,并没有添加条目 服务代码: sampleApp.factory('Brand', function ($resource) { return $resource('http://<mydomain>/api/v1/brands/:id'); }); 这里怎么了?有人能帮上忙吗?要转换为以表单编码而不是默认的application/json发送,下面的

我想在mysql表中添加一个新条目。我从一个高级restful客户端测试了API。很好用

但当我尝试使用angular js时,并没有添加条目

服务代码:

sampleApp.factory('Brand', function ($resource) {
   return $resource('http://<mydomain>/api/v1/brands/:id');
});

这里怎么了?有人能帮上忙吗?

要转换为以表单编码而不是默认的
application/json
发送,下面的示例是从

您还可以在应用程序的配置阶段为所有
$http
设置全局默认值

还可以在
$http
文档中查找将序列化程序作为字符串名传递的替代方法


如果您使用的是jQuery,那么序列化程序与

相同,您能否向我们显示对您的请求的响应(
$resource(
)http:///api/v1/brands/:id“
)首先要开始的是浏览器开发工具网络,并检查实际的请求,以查看到底发送了什么…状态、url等以及正文中的服务器响应。您必须隔离服务器端和客户端问题。在restful中进行测试时,客户端请求也以
application/json
?或form encoded?@SherlockedNguyen这是rrest API的响应。{“error”:false“message”:“Brand created successfully”“Brand_id”:“334”}@charlietfl当使用rest客户端内容类型进行测试时,其内容类型为application/x-www-form-urlencoded
$scope.brand = new Brand();
$scope.brand.id = parseInt($scope.Brands[$scope.Brands.length-1].id, 10) + 1;
$scope.brand.name = $filter('toTitleCase')($scope.NewBrand.name);  
$scope.brand.image = '/images/brands/' + $filter('toLowerCase')($scope.NewBrand.name) + '.png'; 


Brand.save($scope.brand, function() {
        alert('data saved');    
        //data saved. do something here.
});
.controller(function($http, $httpParamSerializerJQLike) {
  //...

  $http({
    url: myUrl,
    method: 'POST',
    data: $httpParamSerializerJQLike(myData),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });

});