大佬教程收集整理的这篇文章主要介绍了AngularJS使用Array参数调用ajax调用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
return $http({ method: 'GET',url: '/api/PatientCategoryApi/PatCat',params: { "numbers[]": [{ First: 999,Second: 888 }]},headers: { 'Content-Type': 'application/Json' } })
该调用生成的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,http://localhost:50849/api/PatientCategoryApi/PatCat?numbers%5B%5D=%5B%7B%22First%22:999,%22Second%22:888%7D%5D params: { "numbers[]": [{ First: 999,http://localhost:50849/api/PatientCategoryApi/PatCat?numbers%5B%5D=%7B%22First%22:999,%22Second%22:888%7D params: { numbers: [{ First: 999,%22Second%22:888%7D
我希望url是http://localhost:50849/api/PatientCategoryApi/PatCat?numbers[0][first]=999&numbers[0][second]=888.因为这是我的Asp.net MVC服务器端代码能够理解和解密数组的唯一@L_801_11@.
一种@L_801_11@是设置url本身以完全保持params,如下所示.以下是有效的.这是我的最后一个选择.
return $http({ method: 'GET',url: '/api/PatientCategoryApi/PatCat?numbers[0][first]=999&numbers[0][second]=888&numbers[1][first]=9999&numbers[1][second]=8888',//params: {...},remove this completely headers: { 'Content-Type': 'application/Json' } })
但我想了解,如何使用params这样做,所以AngularJS会为我做这件事.
$http({ ... params: { "numbers": [{ First: 999,paramserializer: '$httpParamserializerJQLike',... });
或者您可以将其设置为配置块中所有$http调用的默认值,如下所示:
angular.module('yourModulename').config(function($httpProvider) { $httpProvider.defaults.paramserializer = '$httpParamserializerJQLike'; });
以上是大佬教程为你收集整理的AngularJS使用Array参数调用ajax调用全部内容,希望文章能够帮你解决AngularJS使用Array参数调用ajax调用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。