zoukankan      html  css  js  c++  java
  • stringify()用法

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
     5     <title></title>
     6     <script type="text/javascript" src="createXHR.js"></script>
     7     <script type="text/javascript" src="test02.js"></script>
     8 </head>
     9 <body>
    10     
    11 </body>
    12 </html>
     1 function createXHR() {
     2     if (typeof XMLHttpRequest != "undefined") {
     3         return new XMLHttpRequest();
     4     } else if (typeof ActiveXObject != "undefined") {
     5         if (typeof arguments.callee.activeXString != "string") {
     6             var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp"];
     7             for (var i = 0, len = versions.length; i < len; i++) {
     8                 try {
     9                     var xhr = new ActiveXObject(versions[i]);
    10                     arguments.callee.activeXString = versions[i];
    11                     return xhr;
    12                 } catch (ex) {
    13                     console.log("异常");
    14                 }
    15             }
    16         }
    17         return new ActiveXObject(arguments.callee.activeXString);
    18     } else {
    19         throw new Error("No XHR object available.");
    20     }
    21 }
     1 var xhr = createXHR();
     2 var contact = {
     3     name: "Ted Jones",
     4     email: "tedjones@some-other-domain.com"
     5 };
     6 xhr.onreadystatechange = function() {
     7     if (xhr.readyState == 4) {
     8         if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
     9             console.log(xhr.responseText);
    10         }
    11     }
    12 };
    13 xhr.open("post", "addcontact.php", true);
    14 xhr.send(JSON.stringify(contact));

    向服务器提交contact内容

  • 相关阅读:
    Drupal忘记管理员密码
    Drupal7新装一个主题时页面白屏,如何设置一个默认主题?
    Drupal7强制把主题恢复到默认主题
    Drupal常用的模块
    网页流量分析系统
    S运算符&&和|| 及其优先级
    Linux crontab命令
    C语言实现文件实时更新
    Linux 查看设置系统语言
    Python沙盒环境配置
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2541459.html
Copyright © 2011-2022 走看看