在下面的代码中,AngularJS $http
方法调用URL,并将xsrf对象作为"请求有效负载"提交(如Chrome调试器网络选项卡中所述).jQuery $.ajax
方法执行相同的调用,但将xsrf提交为"Form Data".
如何让AngularJS将xsrf作为表单数据而不是请求有效负载提交?
var url = 'http://somewhere.com/';
var xsrf = {fkey: 'xsrf key'};
$http({
method: 'POST',
url: url,
data: xsrf
}).success(function () {});
$.ajax({
type: 'POST',
url: url,
data: xsrf,
dataType: 'json',
success: function() {}
});
Run Code Online (Sandbox Code Playgroud) 您是否知道将Javascript对象编码为string
可以通过GET
请求传递的快速而简单的方法?
不jQuery
,没有其他框架 - 只是简单的Javascript :)
我已经看到以下SO问题通过GET请求使用AngularJS'$ http服务发送数组和从Angular $ http POST传递数据数组.但那里建议的解决方案似乎对我不起作用.我特别关注数组对象.
我有以下AngularJS ajax调用数组参数
return $http({
method: 'GET',
url: '/api/PatientCategoryApi/PatCat',
params: { "numbers[]": [{ First: 999, Second: 888 }]},
headers: { 'Content-Type': 'application/Json' }
})
Run Code Online (Sandbox Code Playgroud)
该调用生成的url似乎对我不起作用.我尝试了各种params的化身,并且生成的url(通过使用fiddler得到它们)如下.
params: { numbers: JSON.stringify([{ First: 999, Second: 888 }]) },
http://localhost:50849/api/PatientCategoryApi/PatCat?numbers=%5B%7B%22First%22:999,%22Second%22:888%7D%5D
params: { "numbers[]": JSON.stringify([{ First: 999, Second: 888 }]) },
http://localhost:50849/api/PatientCategoryApi/PatCat?numbers%5B%5D=%5B%7B%22First%22:999,%22Second%22:888%7D%5D
params: { "numbers[]": [{ First: 999, Second: 888 }]},
http://localhost:50849/api/PatientCategoryApi/PatCat?numbers%5B%5D=%7B%22First%22:999,%22Second%22:888%7D
params: { numbers: [{ First: 999, Second: 888 }]},
http://localhost:50849/api/PatientCategoryApi/PatCat?numbers%5B%5D=%7B%22First%22:999,%22Second%22:888%7D
Run Code Online (Sandbox Code Playgroud)
我希望网址为http:// localhost:50849/api/PatientCategoryApi/PatCat?numbers …