I was looking if there was a way to stop an already running AJAX request, like we can stop an http request using browser stop button. Yes there is a way to stop it using abort() method of the XMLHttpRequest object . More details about this here http://www.quirksmode.org/blog/archives/2005/09/xmlhttp_notes_a_1.html
Archive for the 'jQuery' Category
XMLHTTP AJAX abort(), jQuery abort()
March 10, 2011jQuery Form serialize method – does not post disabled fields
February 24, 2011http://api.jquery.com/serialize/
Today I had a problem where I had some disabled fields which were not getting serialized, I got two solutions for this
- After serialize call, have code to get disabled fields name, value and append to the query string
- Or Instead of using disabled attribute , use readonly attribute (http://www.htmlcodetutorial.com/forms/_INPUT_DISABLED.html
Validate/Revalidate a single field using jQuery validator
February 23, 2011If you have a requirement to just do a single field validation, instead of calling the form validate method which will validate all the fields, then you have to use valid() method on the element
For example if your form has field
<input type="field" name="username" id="username"/>
to validate only username field, use code
jQuery('#username').valid()
But of course you have to link the jQuery validator plugin with your form before you call this method
Related Stack overflow post link here – http://stackoverflow.com/questions/1378472/jquery-validate-can-i-re-validate-a-group-of-fields-after-changing-one
jQuery JSONP (JSON with padding) – success method not called
February 23, 2011Possible reasons for JSONP success method not getting called
-
In jQuery.getJSON method check if you are adding the
callback=?param to your URL -
Check if your server code serving JSONP request is returning proper JSONP response,
For example sample server JSONP java code and response taken from IBM Developerworks article given below,
Java code
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String jsonData = getDataAsJson(req.getParameter("symbol"));
String output = req.getParameter("callback") + "(" + jsonData + ");";resp.setContentType("text/javascript");
PrintWriter out = resp.getWriter();
out.println(output);
}
JSONP Response Format
jsonp1232617941775({"symbol" : "IBM", "price" : "91.42"});
To get a good understanding of JSONP you can read this IBM Developerworks article http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
jQuery Validator – Error: $.validator.methods[method] is undefined
February 22, 2011Error: $.validator.methods[method] is undefined
I was getting this error when using jQuery validator, found the reason for this error was because I didn’t define the custom validator methods which I had assigned in the validation rules. More about jQuery custom validation method here – http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage
jQuery validation plugin , validate only visible fields
February 17, 2011Refer this Stack overflow post for the solution
http://stackoverflow.com/questions/1802177/jquery-validation-only-for-visible-controls
Pasting code from the post below
$("#registerform").validate({ignore:":not(:visible)"});
qTip – Excellent jQuery Tooltip plugin
February 15, 2011If you are looking for a jQuery tooltip plugin to use for your project, http://craigsworks.com/projects/qtip/ is the right one for you.
It gives full flexibility in customizing the appearance and the behavior. Also the default settings are good, so with just couple of lines, you can put this plugin to real use in your project.
Another important aspect is its working fine in both IE8, Firefox and Chrome. The tooltip shows with rounded borders in all the browsers, and its achieving the rounded borders without images, which is cool.
jQuery Template plugin html in variables
January 25, 2011If you pass html content in the template variables, you have to use {{html ..}} format to make sure that the html content gets converted into real html elements.
See this Stack overflow post http://stackoverflow.com/questions/4570222/htmlentities-equivalent-in-jquery-template-plugin
And this documentation – http://api.jquery.com/template-tag-html/
jQuery not executing script tags in ajax load
January 11, 2011This happens when the script code is not correct , or if the script code is a JSON string then the string may not be well formed.