首页 > Web开发 > 详细

js传递数据一些方式

时间:2014-11-24 16:58:22      阅读:267      评论:0      收藏:0      [点我收藏+]

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) {
      //请求返回后执行的操作;
    };
  })
};

js传递数据一些方式

原文:http://www.cnblogs.com/lw9413/p/4118746.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!