zoukankan      html  css  js  c++  java
  • js传递数据一些方式

    1.用Image对象的src属性

    var img = new Image();

    img.src = "http://www.xxx.con/?data1=1";

    创建Image对象,通过其src属性可以向xxx地址传递数据,后台php可以通过GET方法获取src属性中“?”以后的数据。

    2.script标签的src属性

    var sc = document.createElement("script");

    scr.type = "text/javascript";

    sc.async = false; //是否异步

    sc.src = "test.php?name=liuwei,crossword=3";

    document.documentElement.appendChild(sc);

    3.通过ajax发送数据

    //ajax函数封装
    function fnAjax(url,cfn) {
      var xmlhttp;
      if(window.XMLHttpRequest){
      xmlhttp = new XMLHttpRequest();
      }else{
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      };
      xmlhttp.onreadystatechange = cfn;
      xmlhttp.open("GET",url,true);
      xmlhttp.send();
    };

    //ajax请求
    function myAjax() {
      fnAjax("http://www.baidu.com/",function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
          //请求返回后执行的操作;
        };
      })
    };

  • 相关阅读:
    [YTU]_2536( C++ 长方体继承自矩形)
    [YTU]_2560(C++继承(改错题))
    [YTU]_2532(投简历)
    [YTU]_2621(B 继承 圆到圆柱体)
    stl
    noip2008双栈排序
    倍增入门水题
    noip模拟【ping】
    dp入门(LIS,LCS)
    【Luogu 1799】数列
  • 原文地址:https://www.cnblogs.com/lw9413/p/4118746.html
Copyright © 2011-2022 走看看