i works in a MVC 4 project, and i have a small problem in my script, this is my script :
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.
if using jquery POST, do:
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
. 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
var url = '/Home/IsReportAlertWebService/?cc=' + cc + '&carNum=' + carNum;
Or simply format a proper data
object instead.
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? and then you can try :
var url = '/Home/IsReportAlertWebService/?cc="+cc+"&carNum="+carNum;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.