Reputation: 751
I'm trying to send some values to my web service on ajax call.
html
<button type="submit" id="gen" class="btn btn-primary" onclick="getval();">
Javascript
$(document).ready(function () {
function getval(){
$.ajax({
url: base_url+"/aa/testService.php",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "GET",
data: {"name" :"abc",age="20"}
success: function (response) {
console.log(response);
}
});
}});
but my error log showing
line 38 "data: {"name" :"abc",age="20"}" - Unexpected " :", expected one of: "}"
why is that?how to resolve this?
Solution-update
remove data:object
and pass values through url url: base_url+"/aa/testService.php?name='abc'"
Upvotes: 0
Views: 50
Reputation: 68
Please follow the solution below.
<button type="submit" id="gen" class="btn btn-primary" onclick="getval();">
function getval(){
$.ajax({
url: base_url+"/aa/testService.php",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "GET",
data: JSON.stringfy({"name": "abc", "age": "20"})
success: function (response) {
console.log(response);
}
});
return false;
}
Upvotes: 0
Reputation: 68645
You have a wrong syntax in the data
property. Replace the =
with :
and add ,
after it.
data: {"name": "abc", age: "20"},
success: function (response) {
console.log(response);
}
Upvotes: 1