Ajax

AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。
AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。

使用教程:
创建 XMLHttpRequest 对象

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

向服务器发送请求

xmlhttp.open(method,url,async);
xmlhttp.send(string);

服务器响应
responseText 或 responseXML

Ajax_第1张图片
Paste_Image.png

JQuery ajax

jQuery.ajax([settings])

项目中使用到的

    $.ajax({
        url: apiUrl + apiName,
        type: 'post',
        data: jsonData,
        cache: false,
        dataType: 'json',
        contentType: 'application/json',
        //timeout: 1000,
        async: asyn,
        beforeSend: function (XMLHttpRequest) {

            if (showLoading) nopCommerce.app.loadPanel.show(loadingMessage); //Show Loading
            XMLHttpRequest.setRequestHeader("Client-Referrer", document.referrer);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("---------ERROR---------", new Date())
            console.log("ERROR", apiName, { request: XMLHttpRequest, textStatus: textStatus, errorThrown: errorThrown });
        },
        success: function (result) {
            resultHandle(apiName, data, done, fail, showLoading, loadingMessage, result, startTime, isWorker);
        },
        complete: function () {
            if (showLoading) nopCommerce.app.loadPanel.hide() //close loading
        }
    });

资料推荐
$.ajax()方法详解

你可能感兴趣的:(Ajax)