Featured post
javascript frameworks prototype to jquery -
i have found following script apparently written using javascript framework prototype.
event.observe(window, 'load', function() { event.observe( 'btnsubmit', 'click', purchasecd); connecttoserver(); }); function connecttoserver() { new ajax.updater( { success: 'cd count', failure: 'errors' }, 'server_side.php', { method: 'get', onsuccess: function(transport) { if (parseint(transport.responsetext)) connecttoserver(); } }); } function purchasecd() { new ajax.updater( { success: 'cd count', failure: 'errors' }, 'server_side.php', { method: 'get', parameters: { num: $('txtqty').getvalue() } }); }
is here able convert script use jquery instead of prototype? don't know prorotype @ don't understand it.
ajax.updater
takes, parameter 1, 2 containers update successful or failed response of request url given in parameter 2.
what script upon page load (i translated below domready not same, jquery convention) ajax request sent server_side.php
. if gets response understands, sends off request, in order keep session alive.
this looks terrible design. if you're going that, want timeout between requests.
another thing that's not neat script every ajax request handled same page - server_side.php
- relying on different parameters instructions on action perform. appear cleaner request different pages different actions.
$(function() { $('#btnsubmit').click(purchasecd); connecttoserver(); }); function connecttoserver() { $.ajax({ url: "server_side.php", success: function(res) { $('#cd count').html(res); if(parseint(res)) connecttoserver(); }, error: function(xhr) { $('#errors').html(xhr.responsetext); } }); } function purchasecd() { $.ajax({ url: "server_side.php", success: function(res) { $('#cd count').html(res); }, data: { num: $('#txtqty').val() }, error: function(xhr) { $('#errors').html(xhr.responsetext); } }); }
- Get link
- X
- Other Apps
Comments
Post a Comment