So I was doing some experimenting with prototype and ajax and discovered something interesting. When I use the first ajax call the response from the server take 53ms. When I use the second on using the prototype functions the request from the server is over 200ms. My question is why, and can it be fixed?
<p><a href="#" onclick="serverSideAlert();">Call server-side function</a></p> <p id="responseTxt"></p> <script type="text/javascript"> function serverSideAlert() { var request = new XMLHttpRequest(); request.open('get', '/jstest/server_response', false); request.send(null); document.getElementById('responseTxt').innerHTML = request.responseText; } </script>
<script src="/javascripts/prototype.js" type="text/javascript"> </script>
<p><a href="#" onclick="updateElement()">Update element </a></p> <p id="response"></p> <script type="text/javascript"> function updateElement() { new Ajax.Request('/jstest/server_response', { onSuccess: function (request) { $('response').update(request.responseText); }}) } </script>
Thanks
Sam Murk