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
1
: 257 At:- 9/29/2017 12:52:11 PM
javascript jQuery Syntax-Error $.get






1 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:- 9/30/2017 8:31:14 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





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