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
  • 相关阅读:
    MySQL 5.7.19 CentOS 7 安装
    cocos2d-x JS 弹出对话框触摸监听(吞噬点击事件遮挡层)
    cocosStudio制作ScrollView并在cocos2dx 3.0中使用。
    cocos2dx JS 游戏切到后台再进入游戏的处理
    使用Eclipse出现make: *** No rule to make target `all'. Stop.解决办法
    cocos2dx 3.13 在Mac平台下配置安卓环境变量
    (已解决)Eclipsez中打不开c++文件,显示Editor could not be initialized.
    延期版本webstorm(解决许可证过期,注册,激活,破解,码,支持正版,最新可用)
    cocos2dx JS 层(Layer)的生命周期
    Cocos2d-JS studio基础控件的使用
  • 原文地址:https://www.cnblogs.com/wade-case/p/3156413.html
Copyright © 2011-2022 走看看