Posts

Showing posts with the label jQuery

The "TypeError: n.curCSS is not a function‏" Error

Yesterday at work we deployed a new version of one of our websites to production after a successful test cycle in our QA and staging environments. However, once the site was deployed to production, a script error, "TypeError: n.curCSS is not a function‏", would appear whenever an attempt was made to display a jQuery UI dialog. This left me scratching my head. It had worked fine in QA and staging, and the code in question had been around for months. It definitely had something to do with a difference in the production environment, but what? The error in question was occurring in a JavaScript bundle being created by the website (which is an ASP.NET MVC 4.5 site) on start-up. I could view the source and see the offending line. After Googling the error message, I learned that it was related to an incompatibility between versions of jQuery and jQuery UI -- but again, this had worked perfectly in the other environments, and for quite some time. How could it be an incompatibilit...

How to Enable jQuery Client-Side Validation in Dynamically Rendered Partial Views in ASP.NET MVC

Recently I was doing some work in an ASP.NET MVC 4 website and was rendering a partial view to a div element via a jQuery AJAX call. I found that when the partial was included in a view from a controller's action method, all the client-side validation worked correctly, but if I rendered the partial view client-side code that was, for example, just getting the partial view by itself and putting into a div element as I was trying to do, the client-side validation wouldn't work. After doing a little research, I learned that the client-side validation needed to be reset after the partial was rendered via the client-script. To that end, I wrote the following JavaScript function to allow quick and easy resetting of client-side validation in cases such as these. Just pass the CSS selector to the partial's parent form to the function shown below. This, of course, assumes that you also have references to the jQuery unobtrusive validation library. function  ResetValidation(formSe...

Finding and Correcting jQuery Version Conflicts

I recently ran into an issue with some new client-side code I'd developed. While everything worked correctly in the dev environment, upon deployment to the test environment I found that some of the jQuery functions were no longer being recognized. Going to the Console tab in Firebug, and entering "$().jquery" into the command prompt at the bottom, revealed the culprit: for some reason, despite my reference to jQuery 1.7.1, the page was now referencing version 1.4.2. The reason why was a part of the build process that occurs in our test environment and not our dev environment, which adds a reference to a minified 1.4.2 when built for the test environment (the pitfalls of differences between dev and test environments being a discussion for another time). One possible solution to correct this was to simply update the version of jQuery being used to 1.7.1, but there was understandable concern that doing so would impact (read: break) things. So I needed a safer solution. T...

"$.ajax is not a function" Error When Using jQuery and Darren Johnstone's ASP.NET Upload/Download Module v2

Lately I've been working with an excellent file upload library for ASP.NET written by a guy named Darren Johnstone. This library allows you to upload files and see a modal dialog and progress bar which indicates the percentage of the file upload having been completed. It doesn't use Flash (or Silverlight for that matter), just good ol' server-side .NET and some AJAX on the client-side. However, it also killed some existing jQuery code I had in place to make some AJAX calls to WCF services. I found I was now getting the following script error: $.ajax is not a function My workaround was to change my jQuery code to not use the $ abbreviation. So, in other words, I changed $.ajax to jQuery.ajax -- then it started working again. I'm not sure what it is about the upload control that affected this, but the workaround is manageable. Now I'll just need to explain to everyone why my code uses the long version instead of the shorter one anytime someone says to me "Hey, ...

jQuery AJAX Calls Not Working In IE8

I recently discovered that some jQuery code I had written for making AJAX calls was not working in IE8, even in Compatibility Mode. Turns out the reason why is that IE8 caches AJAX GET requests. Changing the calls to POST instead of GET corrected the problem. I hope this helps anyone else having this same issue.

How To Sort Elements By ID In jQuery

I recently came across an issue wherein I needed to be able to sort a set of HTML elements by their IDs. I was retrieving a wrapped set with jQuery, but didn't know how to sort them. I found a blog post by a guy named Bill Richards which can be found here . This put me on the right track and allowed me to solve this issue. My solution is a little different than his, but it was his post that showed me the solution to this problem and saved me a lot of time. Also, a comment left there by a guy named Tom helped as well. Thanks guys! To sort elements with jQuery, all you need to do is create a function that will do the actual sorting (comparing two elements) and then pass the name of this function to the sort() method (using jQuery 1.3.2 or higher). Here is a function which will sort elements by ID: function sortByID(a, b) {    return a.id > b.id ? 1 : -1; }; To use this function to sort a wrapped set, you can call it inline with your code which creates the set by passing t...

How To Get The Selected RadioButton From A List Of Element IDs Using jQuery

I've been doing some work with jQuery lately and now that I've begun digging into it am truly impressed at how much you can do with it so easily. Here's a quick line of code that will take a string of element IDs belonging to RadioButtons, find the one that's selected, and display an alert box with it's value: alert("Selected radio button value: " + $(radioButtonIds).filter(":checked").get(0).value); The format of the string containing the RadioButton IDs would look something like this: "#rdoFirstChoice, #rdoSecondChoice, #rdoThirdChoice"

Crazy Internal Server Error When Developing With WCF and AJAX with jQuery

I've been doing some development lately involving calling WCF services from client-side script using jQuery's ajax function, and ran into some strange behavior. I had some code written that would run successfully without error, but then added some additional, un-related code, which would also attempt to call a WCF service via jQuery and AJAX. The original, working code remained untouched. The new code would be unsuccessful -- however, the old, previously working code would now also fail. The error was Error 500, Internal Server Error . Stopping and restarting the development server didn't solve the issue, nor did exiting and restarting Visual Studio. Even rebooting my machine didn't help. It just didn't make any sense. I finally resolved the problem by deleting the Temporary ASP.NET files for the site. By default, these are located in C:\WINDOWS\Microsoft.NET\Framework\(Framework Version)\Temporary ASP.NET Files , in a sub-folder matching the name of your site. Not...