I am getting the error "SyntaxError: Invalid shorthand property initializer" in my Chrome console, after writing this code of javascript/jquery
var i = 1;
$(document).on('click', '.AddMoreaddress', function () {
$.get('/Mpa/Company/Addreses', { Id:i}, function (data) {
i++;
$("#Addmore").append(data);
})
})
Before writing this code on the page, I wasn't getting any error and it was working fine, so what's the issue in this and how can I resolve it?
thanks
Because it is not correct way of assigning value in jQuery-javascript, you need to assign value using
:
instead of =
, So your code should be like this
var i = 1;
$(document).on('click', '.AddMoreaddress', function () {
$.get('/Mpa/Company/Addreses', { Id=i}, function (data) { // here Id:i instead of Id=i
i++;
$("#Addmore").append(data);
})
})
When assigning values inside {} in javascript, use : instead of =
For example:
This is incorrect
var options = {
host= 'localhost',
port= 8080,
}
This is correct
var options = {
host: 'localhost',
port: 8080,
}
Thanks
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly