admin管理员组

文章数量:1356774

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?

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?

Share Improve this question asked Mar 3, 2013 at 6:45 Alan CoromanoAlan Coromano 26.1k55 gold badges140 silver badges215 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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

Do you mean this?

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

本文标签: javascriptCannot use 39in39 operator to search forin undefinedStack Overflow