[英]how to get URL with two parameters in javascript?
i works in a MVC 4 project, and i have a small problem in my script, this is my script : 我在MVC 4项目中工作,我的脚本中有一个小问题,这是我的脚本:
function IsReportCheckpoint(cc,carNum) {
var url = '/Home/IsReportAlertWebService/'+cc+',' + carNum;//here my problem
$.ajax({
type: "Post",
url: url,
data: {},
datatype: 'json',
});
}
$(function () {
$("input[name=Report]").on('click', function () {
var carNumber = $(this).data('carnum');
IsReportCheckpoint(c,carNumber);
});
});
my problem is the script consider the two parameters in the URL as one parameter, so please if someone has any idea i will be very appreciative. 我的问题是脚本将URL中的两个参数视为一个参数,因此,如果有人有任何想法,我将不胜感激。
if using jquery POST, do: 如果使用jQuery POST,请执行以下操作:
var url = '/Home/IsReportAlertWebService';
$.ajax({
type: "POST",
url: url,
data: { 'cc' : cc, 'car_num' : carNum },
datatype: 'json',
success: function( response ) {
//response from server here
}
});
They way you are formatting it, you're not sending any parameters at all. 他们用这种方式格式化它,根本不发送任何参数。 A propertly formatted URL with query parameters look like this: http://host/path?param1=param1Value¶m2=param2Value
. 具有查询参数的格式正确的URL如下所示: http://host/path?param1=param1Value¶m2=param2Value
。 I don't know how your backend expects the url to be, or what the name of your parameters are, but I would suspect that it should be 我不知道您的后端期望url是什么,或者您的参数名称是什么,但是我怀疑它应该是
var url = '/Home/IsReportAlertWebService/?cc=' + cc + '&carNum=' + carNum;
Or simply format a proper data
object instead. 或者只是简单地格式化适当的data
对象。
Url parameters is probably what you are looking for and are created like this: 网址参数可能是您要查找的参数,其创建方式如下:
/path/to/my/webapp?cc=somevalue&carNum=453
The first Url parameter has a '?' 第一个网址参数具有“?” before it and all the others are separated by '&'. 之前,所有其他字符之间均以“&”分隔。
check this : Encode URL in JavaScript? 检查一下: 用JavaScript编码URL吗? and then you can try : 然后您可以尝试:
var url = '/Home/IsReportAlertWebService/?cc="+cc+"&carNum="+carNum;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.