javascript - Execute this Strange function -


i working on project , on how execute function in javascript.

i not familiar seeing '$' in code before function in js that. should write in console if using js engine such chrome of phantomjs execute function.

<script language="javascript"> $(function () {     $(".cb-js-cc").on('click', function () {         $.ajax({             type: "post",             url: "overview.aspx/cc",             data: "{ reservationversionid: " + $('.js_reservationversionid').val() + "}",             contenttype: "application/json; charset=utf-8",             datatype: "json",             success: function (msg) {                 if (msg && msg.d) {                     alert(msg.d);                 }             }         });     }); }); </script> 

the use of $(function () { ... } ) shorthand notation $(document).ready(function () { ... });. function automatically execute when page finishes loading, , bind click event whatever element tied class 'cb-js-cc'. because function anonymous, won't able trigger via javascript code. if need programmatically trigger event, can use $.click():

$('.cb-js-cc').click(); 

rewriting function not anonymous , can executed at-will:

<script language="javascript">     function myfunc() {         $.ajax({             type: "post",             url: "overview.aspx/cc",             data: "{ reservationversionid: " + $('.js_reservationversionid').val() + "}",             contenttype: "application/json; charset=utf-8",             datatype: "json",             success: function (msg) {                 if (msg && msg.d) {                     alert(msg.d);                 }             }         });     }      myfunc(); </script> 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -