[英]How to pass dates as parameters in Ajax url get call?
I have an Ajax call that tries to populate a highchart
by calling an api
.我有一个 Ajax 调用,它试图通过调用api
来填充highchart
。 I am trying to access date values from ViewBag
and passing them to the AJAX
url, I end up getting an error我试图从ViewBag
访问日期值并将它们传递给AJAX
url,我最终得到一个错误
jQuery.Deferred exception: Jun is not defined ReferenceError: Jun is not defined jQuery.Deferred 异常:未定义 Jun ReferenceError:未定义 Jun
the value from the ViewBag looks like June-2022
. ViewBag 中的值类似于June-2022
。 The ajax implementation looks like ajax 实现看起来像
$.ajax({
url: 'api/getProvinceData/'+ @ViewBag.reportinPeriod,
type: 'GET',
success: function (data) { }
});
so the complete api with the values filled up should look like when it gets the value in the ViewBag所以填充了值的完整 api 在获取 ViewBag 中的值时应该看起来像
url: 'api/getProvinceData/Jun-2022'
Why am I getting Jun is undefined in Ajax, while I am just accessing the value directly from the ViewBag?为什么我在 Ajax 中得到 Jun 未定义,而我只是直接从 ViewBag 访问值? Any help is appreciated.任何帮助表示赞赏。
Because you are calling a view it will render it as 'api/getProvinceData/'+ Jun-2020,
so the best way to access it is to just have it inside the quotes and not concatenate it so it will be因为您正在调用一个视图,所以它会将其呈现为'api/getProvinceData/'+ Jun-2020,
因此访问它的最佳方法是将其放在引号内而不是将其连接起来
$.ajax({
url: 'api/getProvinceData/@ViewBag.reportinPeriod',
type: 'GET',
success: function (data) { }
});
and it will make the api correctly as它将使api正确地作为
'api/getProvinceData/June-2022
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.