Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: missing : after property id

I'm getting the following error: missing : after property id in line

data:{$("#msgForm").serialize() + "&field=msg_from"}

The code looks like the following:

$("#msg_from").autocomplete({
  source:
    function (req, resp){
      $.ajax({
       url: "autocompl.asp",
       data:{$("#msgForm").serialize() + "&field=msg_from"}
      });
    }
}); 

Any clue?

like image 541
Magda Muskala Avatar asked Dec 27 '22 17:12

Magda Muskala


2 Answers

in your case it should be:

data: $("#msgForm").serialize() + "&field=msg_from"

in other cases, when using {}, you also need a key:

data: {'something': $("#msgForm").serialize() + "&field=msg_from"}
like image 68
Sascha Galley Avatar answered Jan 08 '23 06:01

Sascha Galley


Remove the { and } from that line:

$("#msg_from").autocomplete({
  source:
    function (req, resp){
      $.ajax({
       url: "autocompl.asp",
       data: $("#msgForm").serialize() + "&field=msg_from"
      });
    }
});

The {} in data: {} is interpreted as object literal, not a code block (terminology?). Object literals are in the form { id: property }, hence the error message.

like image 23
Lekensteyn Avatar answered Jan 08 '23 07:01

Lekensteyn