zoukankan      html  css  js  c++  java
  • Ajax

    1. XMLHttpRequest is the object that enables the JavaScript code to make asynchronous HTTP server requests. This allows you to initiate HTTP requests and receive responses from the server in the background, without requiring the user to submit the page to the server. This feature, combined with the possibility to manipulate the web page using DOM and CSS, allows you to implement responsive functionality and visual effects backed with live data from the server, without the user experiencing any visual interruptions. This is AJAX.
    2. From: http://www.cristiandarie.ro/asp-ajax/Async.html
    3. The typical sequence of operations when working with XMLHttpRequest is as follows:
      1. Create an instance of the XMLHttpRequest object.
      2. Use the XMLHttpRequest object to make an asynchronous call to a server page, defining a callback function that will be executed automatically when the server response is received.
      3. Read the server's response in the callback function.
      4. Update the web page using the data received from the server.
      5. Go to step 2
    4. The following JavaScript function creates an XMLHttpRequest instance by using the native object if available, or the Microsoft.XMLHttp ActiveX control for visitors that use Internet Explorer 6 or older:
      // creates an XMLHttpRequest instance
      function createXMLHttpRequestObject()
      {
        // xmlHttp will store the reference to the XMLHttpRequest object
        var xmlHttp;
        // try to instantiate the native XMLHttpRequest object
        try
        {
          // create an XMLHttpRequest object
          xmlHttp = new XMLHttpRequest();
        }
        catch(e)
        {
          // assume IE6 or older
          try
          {
            xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
          }
          catch(e) { }
        }
        // return the created object or display an error message
        if (!xmlHttp)
          alert("Error creating the XMLHttpRequest object.");
        else 
          return xmlHttp;
      }
    5. This function uses the JavaScript try/catch construct, which is a powerful exception-handling technique that was initially implemented in OOP (Object Oriented Programming) languages. Basically, when an error happens at run time in the JavaScript code, an exception is thrown. The exception is an object that contains the details of the error. Using the try/catch syntax, you can catch the exception and handle it locally, so that the error won't be propagated to the user's browser. try/catch :
      try
      {
        // code that might generate an exception
      }
      catch (e)
      {
        // code that executes if an exception was thrown in the try block
        // (exception details are available through the e parameter)
      }

      You place any code that might generate errors inside the try block. If an error happens, the execution is passed immediately to the catch block. If no error happens inside the try block, then the code in thecatch block never executes.Run-time exceptions propagate from the point they were raised, up through the call stack of your program. The call stack is the list of methods that are being executed. So if a function A() calls a functionB() which at its turn calls a function called C(), then the call stack will be formed of these three methods. If an exception happens in C(), you can handle it using a try/catch block right there. If the exception isn't caught and handled in C(), it propagates, to B(), and so on. The final layer is the web browser. If your code generates an exception that you don't handle, the exception will end up getting caught by the web browser, which may display an unpleasant error message to your visitor.

    6. Another technique is to use a JavaScript feature called object detection. This feature allows you to check whether a particular object is supported by the browser, and works like this:
      if (window.XMLHttpRequest)
      {
        xmlHttp = new XMLHttpRequest();
      }
    7. n
    8. n
    9. n
    10. n
    11. n
    12. n
  • 相关阅读:
    p3c安装使用 编码规范扫描 阿里巴巴出品,挺好用的
    Ideal test 不执行main方法了
    Maven 3-Maven依赖版本冲突的分析及解决小结
    (String)强制转换、toString()和String.valueOf()的区别
    Linux tail 命令详解
    iconv的安装和使用
    daemon函数的原理及使用详解
    SQL Sever 2012 如何建立数据库连接
    Navicat Premium 将sqlserver 数据库 导入mysql 中
    MySQL也有潜规则 – Select 语句不加 Order By 如何排序?
  • 原文地址:https://www.cnblogs.com/wade-case/p/3156413.html
Copyright © 2011-2022 走看看