Alan Coromano
Alan Coromano

Reputation: 26018

Cannot use 'in' operator to search for .... in undefined

I have got a following code:

function sendAjax(myData){
  $.ajax({
      type: myData["verb"],
      url: "url" in myData["url"] ? myData["url"] : "/default123",
      //..............

If I don't pass "url" as a key then I'll get the error of "Uncaught TypeError: Cannot use 'in' operator to search for 'url' in undefined ".

How do I get rid of it?

Upvotes: 0

Views: 13952

Answers (2)

Josh
Josh

Reputation: 3284

url : "url" in myData ? myData["url"] : "/default123"

Upvotes: 3

elclanrs
elclanrs

Reputation: 94101

Do you mean this?

url: myData["url"] || "/default123",

Upvotes: 2

Related Questions