jquery

/Tag: jquery

Organize JavaScript and jQuery events – DOM-ready execution

By |2012-04-19T17:32:31+00:00April 19th, 2012|Categories: Programming|Tags: , |

In complex websites javascript and jquery events can conflict with each other, especially if you are using the same javascript files for different website pages. There are many techniques to solve this issue, and I found a good solution by following these articles: Automate firing of onload events Markup-based unobtrusive comprehensive DOM-ready execution Extending Paul Irish’s comprehensive DOM-ready execution But while using this technique I faced an issue, I wanted to call more than one init function on the same page load, for example if I have my page as sections: header, login popup, inner form, footer. And each section needs [...]

Avoid sending Ajax request parameters in query string style

By |2011-06-29T17:36:36+00:00June 29th, 2011|Categories: Technical|Tags: , , |

While reviewing some code, I found someone calling jQuery Ajax like this: $.ajax({       type: "POST",       url: "/AddPost",       data:  "postText="+ PostText ,       dataType: "json",       success: function (status) {        }}); //$.ajax({ And as you see in the previous code, it is sending the data using this line: data: "postText="+ PostText , This is like a query string style, this will work well but image the user inserted a special char in PostText, such as ?? you will get on the server un expected value “"jQuery15107041011152323335_1309357585354"” So never use this style while dealing with Ajax calls, you need to post it in JSON [...]