Why not just using ajax for Page Requests to load the page content?

后端 未结 9 908
醉话见心
醉话见心 2021-01-13 07:47

Many web pages load all of their content to change very little information.

Now I would like to know why shouldn\'t the developers just use ajax for the main page re

相关标签:
9条回答
  • 2021-01-13 08:22

    Well, you can always add the onclick event unobtrusively using jquery and stop the normal URL handling.

    Eg:

    HTML

    <a id="ajaxify-this" href="my-working-url">Click me to do AJAXy stuff if you have javascript</a>
    

    then Javascript

    $(document).ready(function() {       
      $("#ajaxify-this").click( function(e) {
           updateContent(); // do something ajaxy with the page
           return false; // stop the click from causing navigation
       })
    }
    
    0 讨论(0)
  • 2021-01-13 08:24

    I'll give you one very good reason.

    If you turn off javascript in the browser it won't work.

    0 讨论(0)
  • 2021-01-13 08:27

    The whole premise really is that with AJAX you don't need to reload the whole page to update a small percentage of that webpage. This saves bandwidth and is usually much quicker than reloading the whole page.

    But if you are using AJAX to load the whole page this is in fact counterproductive. You have to write customised routines to deal with the callback of the AJAX data. Its a whole lot of extra work for little to no increase in performance.

    General rule for where to use AJAX: If your updating >50% of your page, just reload, else use AJAX.

    0 讨论(0)
提交回复
热议问题