如何在具有多个参数的 angularjs 中发送 POST? [英] How to send POST in angularjs with multiple params?

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

问题描述

我想使用 angularjs HTTP post 服务发送多个参数.

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

这是客户端代码:

$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") });

这是服务器端代码:

// 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?

推荐答案

考虑带有参数 useremail

params 对象将是

params object will be

 var data = {user:'john', email:'john@email.com'};
    $http({
      url: "login.php",
      method: "POST",
      params: data
    })

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

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