Reputation: 595
I would like to pass 2 parameters in $.ajax call.
Here is my code :
function getStatistic6() {
var response;
var allstat6 = [];
var dstart = "01/01/2014";
var dend = "31/03/2014";
$.ajax({
type: 'GET',
url: 'http://localhost:52251/Service1.asmx/Statistic_6_Entete',
data: "start='" + dstart + "'" + " end='" + dend +"'",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
response = msg.d;
for (var i = 0; i < response.Items.length; i++) {
var j = 0;
allstat6[i] = [response.Items[i].Date, response.Items[i].Piece, response.Items[i].Tiers, response.Items[i].AmoutHT, response.Items[i].AmountTTC, response.Items[i].Quantite];
}
fillDataTable6(allstat6);
$('table').visualize({ type: 'line' });
},
error: function (e) {
alert("error loading statistic 6");
}
});
}
I have an error : "Invalid JSON primitive: end='31/03/2014'."
With one parameter, I do well.
How to pass the 2 parameters?
Upvotes: 0
Views: 92
Reputation:
Small correction, remove 's and add "&" between each value.
data: "start=" + dstart + "&" + " end=" + dend
Upvotes: 0
Reputation: 4624
data: {start: dstart, end: dend }
EDIT Try with:
data: {"start": dstart, "end": dend }
Upvotes: 0
Reputation: 388446
You can pass it as an object as given below
function getStatistic6() {
var response;
var allstat6 = [];
var dstart = "01/01/2014";
var dend = "31/03/2014";
$.ajax({
type: 'GET',
url: 'http://localhost:52251/Service1.asmx/Statistic_6_Entete',
//pass it as an object, jQuery will serialize it for you
data: {
start: dstart,
end: dend
},
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
response = msg.d;
for (var i = 0; i < response.Items.length; i++) {
var j = 0;
allstat6[i] = [response.Items[i].Date, response.Items[i].Piece, response.Items[i].Tiers, response.Items[i].AmoutHT, response.Items[i].AmountTTC, response.Items[i].Quantite];
}
fillDataTable6(allstat6);
$('table').visualize({
type: 'line'
});
},
error: function (e) {
alert("error loading statistic 6");
}
});
}
Upvotes: 2