jquery - JavaScript Code Organization Suggestions/Code Review -
-
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.
-
-
-
-
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
Post a Comment