Fixed a condition for appending query string to URL using jQuery