如何发送POST与多个PARAMS angularjs? [英] How to send POST in angularjs with multiple params?

查看:95
本文介绍了如何发送POST与多个PARAMS angularjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用angularjs HTTP发布服务发送多个参数。

下面是客户端code:

  $ http.post(HTTP://本地主机:53263 / API /产品/,[$ scope.product,$ scope.product2])。
        然后(功能(数据,状态,头,配置){警报(成功)},
             功能(数据,状态,头,配置){警报(错误)});

下面是服务器端的code:

  // POST API /<控制器与GT;
公共无效后([FromBody]产品的产品,[FromBody]产品产品2)
{
    VAR productRepository =新ProductRepository();
    VAR新品推荐= productRepository.Save(产品);
}

但是,当我做后,我得到的错误。
任何知道我做错了?


解决方案

  VAR INDATA = {参数:'VAL1',......}
    $ HTTP({
    网址:time.php
    方法:POST,
    params:一个INDATA
    })

I want to send multiple parameters using angularjs HTTP post service.

Here is client side code:

$http.post("http://localhost:53263/api/Products/", [$scope.product, $scope.product2]).
        then(function (data, status, headers, config) { alert("success") },
             function (data, status, headers, config) { alert("error") });

Here is server side code:

// POST api/<controller>
public void Post([FromBody]Product product,[FromBody]Product product2)
{
    var productRepository = new ProductRepository();
    var newProduct = productRepository.Save(product);
}

But when I make the post I get error. Any idea what I am doing wrong?

解决方案

 var Indata = {param:'val1',.....}
    $http({
    url: "time.php",
    method: "POST",
    params: Indata
    })

这篇关于如何发送POST与多个PARAMS angularjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆