jquery - JavaScript Code Organization Suggestions/Code Review -


  1. I am working on a large site that has a lot of custom (page specific JS) Main. JS and Page-specific There are JS files.

  2. P> I am currently specifying all onclick events inline like onclick = "MYSITE.message.send ... - is this a better way? Multiple $ (" # button " (Function () {}); seems like more work ...

      var MYSITE = MYSITE: {}; var MYSITE {bookmark: {add: Function (contentId, UserId) {var data = {contentId: contentId, userId: userId}; $ .ajax ({url: "/ left / bookmark /", type: "post", data: data, complete: function ) {If (Response.error) {alert (response.error);} else {alert ("Successful Security ");}}});}} Message: {/ * & lt; a onclick =" MYSIT E.message.send ( '1234', '1234'); "Href =" javascript: zero (0); "& Gt; Bok Mark & ​​lt; / a & gt; * / Send: function (contentId, userId) {var data = {contentId: contentId, userId: userId}; $ .aex ({url:" / left / bookmark / ", Type:" post ", data: data: complete: function (response) {if (reaction. Panic) {warning (panic panic);} and {alert (" success ");}}});} }  

    }

If you have a div element with a tag, you can use the jquery delegate method

 

And you can dynamically get 'contentId' and 'userId'.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -