Magda Muskala
Magda Muskala

Reputation: 73

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?

Upvotes: 4

Views: 2187

Answers (3)

Sascha Galley
Sascha Galley

Reputation: 16091

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"}

Upvotes: 5

Naftali
Naftali

Reputation: 146320

Your data should look like this:

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

Upvotes: 2

Lekensteyn
Lekensteyn

Reputation: 66465

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.

Upvotes: 3

Related Questions