javascript

JavaScript asynchronous race condition

There is array of objects, which are expanded with parallel ajax requests. When last request is done array should be processed. The only solution i see is: function expandArray(objects, callback){ number_of_requests=objects.length-1; for(i in objects){ $.getJSON(request,function(){ //expanding array ...

Splitting a string with curly braces as delimeters?

'{5}<blah>{0}</blah>' i want to turn that into: ['{5}', '<blah>', '{0}', '</blah>'] i currently use: ________.split(/({.*?})/); but this fails when curly brace is the first character as in the case: '{0}<blah>' which gets turned into: ['', '{0}', '<blah>'] ... a 3 element array, not a 2 what's wrong with my regex? Thanks! ...

Rails: do we have anything built-in to output a ruby array as arguments to a javascript function call?

Hi, Here's what I want, in wishful code: in my controller action: @javascript_function_args = [ "foo", "bar", 1, [2, 3], { :zort => 'narf', :nom => 'cake' }] in my erb view: <script … > performAwesome(<%= @javascript_function_args.to_js_args %>); </script> or, even better: <%= call_javascript_function :performAwesome, *@java...

jQuery sort by rating (desc) and hide divs based on value

Hello, I am trying to achieve the following. I have a dozen divs with something like: <div id=1><div>test 1</div><div>4</div></div> <div id=2><div>test2</div><div>1</div></div> <div id=3><div>test3</div><div>6</div></div> <div id=4><div>test4</div><div>3</div></div> <div id=5><div>test5</div><div>2</div></div> <div id=6><div>test6<...

XmlHttpObject does not change its readyState.

I'm trying to implement a chat client using JavaScript. The client is constructed using the following constructor: function ChatClient(endpointUrl) { this.xmlHttp = createXmlHttpRequest(); this.endpointUrl = endpointUrl; me = this; setInterval('me.receiveMessages()', FETCH_MESSAGES_INTERVAL); } function createXmlHttpR...

How to increase performance of jQuery

i have an chat application written in jsp and jQuery. I have used the setTimeout method for threads who are continuously posting request in some URL. My browser is hanging after some time and cpu utilization is very high. Is there any way to increase performance of JS? ...

Fix Web App bugs by reloading page, or reloading script / external resource

Say I just found a bug involving javascript workflow in a web app. Most of the time I will fix the bug and reload the page. Unfortunately this is a time consuming process reloading the page all the time. Does anybody else save time by reloading updated Javascript / CSS without reloading the page. Are there any tools to help make this...

How are cells of a table impacted by declaring an event in a col element?

When an event, such as onclick, is declared in a col element for an HTML table does that event impact the cells referenced by the col element? Is the event ignored? Does something else happen? ...

Javascript form submital works in webkit, fails elsewhere

I've written this code to try and send a url as a post value to the same page. The code worked great in chrome and safari... but fails in FF3 and IE (the last one I could care less about, but I need it to work in firefox). In FF3 and IE it opens up a blank new tab. What should I know about the differences between the way webkit and the o...

jQuery AJAX polling for JSON response, handling based on AJAX result or JSON content

I'm a novice-to-intermediate JavaScript/jQuery programmer, so concrete/executable examples would be very much appreciated. My project requires using AJAX to poll a URL that returns JSON containing either content to be added to the DOM, or a message { "status" : "pending" } that indicates that the backend is still working on generating a...

What does the !! operator (double exclamation point) mean in JavaScript?

I've just walked into this code: val.enabled = !!enable and have no idea what does "!!" do... I googled JavaScript operators but haven't found this one. ...

Making a form re-enabled after it has been disabled, using jQuery.

I currently have my code set to disable the submit button when the field is submitted. Is there a way I can make it re-enable the submit button later? The first half of my code. $("#segment").submit(function () { $(':submit').attr('disabled', 'disbled'); The second half of my code. if (data == 'success') { $("#se...

Use of $get in C# ASP.NET AJAX

What is the use of $get('').value in ASP.NET AJAX? Is it different from the usual C# get and set properties of the same?? ...

Modifying jQuery $.ajax() success method during request

In the web app I am working on there is potential for very long running ajax queries. I'm using jQuery's $.ajax method to do something like: this._xhr = jQuery.ajax({ type: "GET", url: "/path/to/service", data: "name=value", success: function(data, message){ // handle a success }, dataType: "json" }); ...

Need to make jquery add css to a table which is added through ajax

I have a webpage... http://beta.charmscorp.com/inspect/projects.php - this webpage is in beta and doesn't currently look super professional and is only half working, also, the server internet connection is slow so it takes a bit to load up the elements properly. Anyways, this page calls other pages through ajax to display in a div. My ...

Facebook javascript users_getInfo getting email

Hi, How can I get the email address of a user from my app? Right now I have it as FB.Facebook.apiClient.users_getInfo(uid, 'last_name, first_name, email_hashes', userInfoCallback); The last_name and first_name does work, but email_hashes gives an empty Object. Am I missing anything? Thanks, Tee ...

Factors for Javascript performance

I understand that the browser does all the work in processing client side scripts (Javascript, JQuery etc), but wanted to know if anything else matters when it comes to performance (Network speed, Speed of the client computer, Server environment) If it's completely dependent on the browser (type and version), is it correct to say that t...

Javascript Clean URL Regex

I am building a CMS news sections with a few fields but the ones notably needed for this question are the "Title" and "URL Reference" fields. When a user enters in an article title I want Javascript/jQuery to replace the text from the Title field and create a "clean" URL fragment by removing any spaces and weird characters with a dash(-...

Is there any way to speed up this solution for a case-insensitive jQuery :contains selector?

I found this solution for a case-insensitive jQuery :contains selector on StackOverflow. It works great, however it comes at the cost of performance. Does anyone else find this solution to be a bit slow? I'm using the :contains selector to search a table. The user types a search string into a textbox. For each keystroke, it searches the...

What listbox event should I use to set scroll position.

on my page, I have a listbox in an update panel. I am successfully trapping the scroll position, however when the update panel refreshes, I'm having trouble finding a suitable javascript event in which to call my function to set the scroll position. Any ideas? i had really hoped that "onAfterUpdate" was going to work, but no... ...