Rectangle 27 0

Solved by adding the whole form that I need into the element, and then making the draggable/droppable callbacks fill in the values the form needs and firing the .submit() which then is handled by jquery-rails.

Making use of jquery-rails (ujs) when creating manual ajax requests - ...

jquery ruby-on-rails ruby-on-rails-3 ujs
Rectangle 27 0

if the XHR requests take longer than the poll period (on average) there will be an increasing queue of pending requests

To avoid this possible case, use a CPS-style coding where the next action is done using the appropriate callbacks. That is, don't start the next request until required (previous request complete: success or failure) -- this approach can still be used to create a manual request queue with a controllable size if numerous outstanding requests are required.

Also, make sure that unused objects are be eligible for reclamation as this is the "standard" cause of a "memory leak" in a GC language.

The code in the post contains nothing that will inherently leak memory. It could possibly be an issue internally with jQuery, but this is just speculation. Additionally, tools like Firebug that monitor XHR/web requests can consume significant amounts of memory so it's something to check and make sure the behavior is not a Heisenberg.

Also, remember that increasing memory usage doesn't not indicate a memory leak unless it grows unbounded. A garbage collection cycle will only occur when the hosts feels like it.

Hi pst, thanks for your feedback and thoughts on this. I tried to use setTimeouts "on success" instead of setIntervals, but unfortunately this doesn't change the problem. I now think that it isnt really a memory leak, but it could be that when you load a bunch of HTML maybe it is attached or in some way bound to the DOM and never released. So (as said in my other comment above), maybe it's a good idea to load some JSON instead and render it. I also think that the problem wouldn't come out in production IF the users wouldn't have the app open 24/7. The production interval is 30 seconds....

...which should be enough time to release the old dom elements. Sadly it happens with IE too (where we don't have firebug actually). I wonder how the "Big players" like facebook or twitter handle this case in their environments (chat, realtime stream and so on).

javascript - Browsers keep eating memory with AJAX + setInterval - Sta...

javascript jquery ajax memory-leaks
Rectangle 27 0

I recommend you use jQuery, instead of creating XmlHttpRequest objects manually, as it manages to solve some compatibility issues between browsers, and makes the whole thing way simpler.

$.post({
    url: "http://example.com/....",
    data: {"username": "your_user_here", "password": "your_password_here"},
    success: function(){
        alert('Success!');
    }
});

Anyways, there are a lot of options there and the topic is quite long to fit in a SO answer, so I recommend you have a look at the jQuery Ajax documentation here: http://api.jquery.com/category/ajax/

$_POST

Sorry, I was remembering incorrectly, but the default behavior of jQuery is to urlencode the POST data, so you'll be fine with reading values from $_POST, when doing requests with the code above..

I'm going AFK, hope this helps, if you have any question, feel free to comment, I'll reply tomorrow..

Actually, jQuery.ajax converts the data setting to a properly encoded querystring api.jquery.com/jQuery.ajax/#jQuery-ajax-settings PHP wouldn't have an issue with processing it.

good that's already the default, I remembered it wasn't but I was wrong..

anyways, may I know the reason for the downvotes? I explained to him how to do that the right & simple way, since: 1. the question is tagged jQuery; 2. it doens't make any sense of directly using xmlHttp objects (that, a part from requiring much more code, will probably only work on a few browsers) and reinvent methods to urlencode forms: everything it's already there in jQuery!

php - How to properly send POST data? - Stack Overflow

php javascript html ajax
Rectangle 27 0

AJAX calls would still be the best solution, but if you don't want to use them, you can always manually create arrays for each of the main options, make an onchange event on the select element which would call the selected array and create another dropdown based on the elements of that array. Hope I didn't make it sound to complicated, since it isn't.

Here's a sample how to extract values with jQuery.

jquery - Dropdown / Select Box Navigation with JavaScript ? - Stack Ov...

javascript jquery html
Rectangle 27 0

If you're adding a click event to a#add_another_file , then you don't need to use :remote => true , because you're making the Ajax request manually.

Also, the click event should prevent the default action from occurring. This can be accomplished by adding event.preventDefault(); to the beginning of the click event's callback. Note that the callback needs to accept the event argument.

I'm following along in Rails 3 In Action, which provided the code. I think using :remote would be the right way. If there should not be a manual $.get(), then I'm confused about how it works period, I'll investigate. And thanks for the event tip!

this answer totally saved me, -> while using backbone events + jquery bind, browsers handled it OK, ie8 though didnt, because of what you explained. Great insight!

jquery - Rails UJS link_to :remote does AJAX GET and normal G...

ruby-on-rails jquery ujs
Rectangle 27 0

The way you are using the jquery ajax call is technically correct. One suggestions I would make is to not build the data string manually as you have. You can pass an object literal to the data parameter and let jquery do the string conversion for you. This has the added benefit of letting jquery perform proper escaping which can sometimes mess with an XMLHttpRequest Other than that, I would recommend using firebug's console.trace() command to see if you are actually making two .ajax calls and why. There is a 'beforeSend' listener that you could set in your ajaxSetup - might be a good place to put it.

jquery ajax call response never returns - Stack Overflow

jquery ajax
Rectangle 27 0

Solved by adding the whole form that I need into the element, and then making the draggable/droppable callbacks fill in the values the form needs and firing the .submit() which then is handled by jquery-rails.

Making use of jquery-rails (ujs) when creating manual ajax requests - ...

jquery ruby-on-rails ruby-on-rails-3 ujs
Rectangle 27 0

The issue seems to be with the Rails asset pipeline using a feature called Turbolinks for sending CSS and JS assets to the browser. Turbolinks uses AJAX to load assets without refreshing the page. Problems can occur with popular javascript and css libraries such as jQuery/Chosen. A developer/user may notice the only way to make the assets work is with a manual browser refresh.

Josh Frankel describes this issue and provides a solution:

gem 'jquery-turbolinks'
app/assets/javascripts/application.js
//= require jquery.turbolinks
//= require jquery
//= require turbolinks
  • Restart any running instances of the Rails server and re-compile assets.

asset pipeline - My rails 4 page specific styles only get applied on p...

ruby-on-rails-4 asset-pipeline
Rectangle 27 0

You could manually construct the partial views in HTML helper methods. However, the feasibility of that approach depends on whether or not the partial views will be reused in other pages. I build a data grid control from scratch using HTML helper methods. Some of my pages have three or four of these data grids managed by a jQuery accordion control to reduce the screen footprint. I chose building an HTML helper for a number of reasons. First, I expected to use this control throughout my applications. Second, I didn't want to burden my views with a bunch of conditional logic. Finally, I wanted to be able to change the grid's configuration (including the model) within the view, so I wouldn't have to recompile every time I changed it. The grid supports both LINQ-to-SQL models and user-defined classes (using reflection), has a built-in pager control and a search mechanism that supports multiple search fields in a grid. I also set up the columns so that they can either display formatted text, link to a controller action or hold a mailto: link. Within the grid itself, you can define the model to populate the grid, optionally set the columns to display, specify the action and controller for creates, and specify a JavaScript function for deletes (because I use the jQuery dialog plugin for confirmation messages). All these changes are managed in the view itself.

Learning how to leverage HTML helper methods gives you the closest thing to ASP.NET server controls that MVC provides.

neil, that sounds fantastic, let me ask you, are you able to update all of these views that you've generated using custom helpers when one action link is called? ie: user clicks something, and i/u need/want to update several parts of the page, in different areas... yes?

this is effectively all i want to do without tightly embedding half my business logic in js & the other half scattered around the server, defeating the point of moving to mvc... i just want to do several partial updates at once, like how you'd do with updatePanels, update them all at once during one callback :)

of course just to add, im doing all this in 100% ajax, reloading entire page is just not an option unless a user is moving to a different page.

The purpose of the helpers is only to assist with the construction of the HTML view. If you're using Ajax, you're probably not going to get away from having to write a reasonable amount of JavaScript, even if it's just to call the appropriate controller action method. My data grid is not Ajax-enabled yet, because I want to make sure it's stable before I start adding the Ajax/jQuery magic.

so if you need to update 4 parts of your page you need to make 4 client-server calls (awch) instead of back in the dreded updatePanel days where you could do it in one call and page lifecycle! ?? oh my god, this is just poor framework design!! as usualy, VS always leaves a bad taste in my mouth once i start getting to know it, should have stuck with webforms!! :(

c# - Simple MVC Question for MVC beginner - Stack Overflow

c# asp.net asp.net-mvc vb.net ajax
Rectangle 27 0

ASP.Net is a server technology that is parsed on the server and creates HTML and JavaScript dynamically which is then passed on to the client. The client browser is technology agnostic; it does not know or care if the server used ASP.Net, Ruby/Rails, PHP, Java, or any other technology to create the HTML and JavaScript. If you are trying to change the output on the client, you must either use JavaScript to make calls to the server to request the new information and then change the data values (Commonly referred to as AJAX, an acronym for Asynchronous JavaScript and XML), or you must do a full Postback to the server and have the server re-render the HTML. Newer ASP technologies (ASP.Net MVC, for example) use a combination of Server Side and JavaScript technologies to make this process less manual, but they are ultimately hiding the implementation of AJAX calls.

After re-reading your post, I believe I understand what you are trying to do. The CommandArgument is a literal string which you are trying to write the value of a variable into before passing it to the client. In order to do this, you need to use the #Eval keyword, i.e. CommandArgument='<%#Eval("item.Code")%>'. This establishes a one way binding for this value in the string property.

I know this. But it doesnt help. The client will recieve an html, no matter if I will write <%:item.Name %> or <asp:button runat="server" OnClick="Add_Click" CommandArgument="blabla"> . Both case translte to HTML on the browser. So why can't it be a combintaion?

Yep, It seems to me that by 'Client Side' He actually means the Markup. Where Client Side is usually used to refer to DHTML functionality.

c# - aspx client side dynamically create asp tags - Stack Overflow

c# asp.net dynamic client-side
Rectangle 27 0

the best is, without a doubt, Zebra_Form, a jQuery augmented PHP library for creating and validating HTML forms: provides both server-side and client-side validation (client-side validation is done using jQuery 1.5.2+) and has a lot of predefined rules that can be used out of the box; custom validation rules (including AJAX-based) can easily be added; has integrated cross-site scripting (XSS) prevention mechanism that automatically strips out potentially malicious code from the submitted data, and also features protection against cross-site request forgery (CSRF) attacks; it prevents automated SPAM posts, out of the box and without relying on CAPTCHAs by using honeypots; forms' layout can be generated either automatically or manually using templates; it's easy to learn, mature, and it is constantly improved;

PHP Framework for form-intensive application - Stack Overflow

php forms frameworks
Rectangle 27 0

Instead of making a manual AJAX request, I advise you to use the remote: true parameter of the form_for:

<%= form_for ..., remote: true do |f| %>
  # your form

Then, in your create action, you can simply do:

def create
  # ...
  respond_to do |format|
    format.html
    format.js {render json: word}
  end
 end

You can read more about the remote option here

However, if you still want to submit your data with your own AJAX request, you can just disable your submit button:

<button type='button' id='some_id'>Submit</button>

Thanks, I removed the button and now is working fine.

jquery - Ajax no redirect - Stack Overflow

jquery ruby-on-rails ajax ruby-on-rails-4
Rectangle 27 0

If you're adding a click event to a#add_another_file , then you don't need to use :remote => true , because you're making the Ajax request manually.

Also, the click event should prevent the default action from occurring. This can be accomplished by adding event.preventDefault(); to the beginning of the click event's callback. Note that the callback needs to accept the event argument.

I'm following along in Rails 3 In Action, which provided the code. I think using :remote would be the right way. If there should not be a manual $.get(), then I'm confused about how it works period, I'll investigate. And thanks for the event tip!

this answer totally saved me, -> while using backbone events + jquery bind, browsers handled it OK, ie8 though didnt, because of what you explained. Great insight!

jquery - Rails UJS link_to :remote does AJAX GET and normal G...

ruby-on-rails jquery ujs
Rectangle 27 0

Behind the scenes jQuery is creating a new DOM element, rather than making a 'copy' of the original. Because of this it doesn't have the event handler of the original. You can either manually re-assign the handlers along with your html() call, or you can use delegate() to add the event, like this:

$("#box").delegate("#buttonName", 'click', function(){
    $("#containerName").toggleClass("hidden");
});

Dear Rory, thank you very much for the explanation and the example. As you can imagine, it instantly solved my problem. Time for me to read up on delegates I would say :)

jQuery html() method unbinding events to elements inside the inner htm...

jquery html events click