SyntaxError: Invalid shorthand property initializer


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

 


Asked by:- Sam
2
: 6030 At:- 9/29/2017 12:52:11 PM
javascript jQuery Syntax-Error $.get







2 Answers
profileImage Answered by:- Vipin

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);

         })

})

2
At:- 9/30/2017 8:29:28 AM Updated at:- 12/24/2022 6:45:17 AM
correct answer, "Id=i" is not a valid way to assign value in javascript Objects 0
By : neena - at :- 10/2/2017 12:06:03 PM


profileImage Answered by:- jon

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

0
At:- 12/24/2022 2:20:14 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use