前端JavaScript:

function ajaxGet(url, obj) {
var request;
if(window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else {
request = new ActiveXObject('Microsoft.XMLHTTP'); // 兼容IE
} request.onreadystatechange = function() {
if(request.readyState === 4) { // 4 请求完成
if(request.status === 200) { // 200 页面成功加载
console.log(request.responseText); // 成功 返回得到的文本
} else {
console.log(request.status); // 失败 返回状态码 如 404
}
} else {
console.log('Requesting');
}
}
/* 解析参数 */
str = '?';
for(key in obj) {
str += (key + '=' + obj[key] + '&');
}
str = str.substr(0, str.length - 1);
/* 发送 */
request.open('GET', url + str);
request.send();
} ajaxGet('ajax.php', {
'type': 'get',
'data': 'test'
}); //get-test

后端PHP:

<!-- ajax.php -->
<?php
echo $_GET['type'] . '-' . $_GET['data'];

原生JavaScript写AJAX

最新文章

  1. Linux(Centos)之安装Nginx及注意事项
  2. 使用MapReduce实现join操作
  3. How to Develop blade and soul Skills
  4. Spring 之autowired
  5. go语言包与包引用
  6. 大话细说ORM
  7. js 动态计算折扣后总价格
  8. asp.net中的<%%>形式的详细用法实例讲解
  9. richTextBox1 转到行号
  10. 如何查詢 SQL Server 資料庫中欄位值為 NULL 的資料(转)
  11. sqlserver2005级联删除
  12. XOR 加密简介
  13. opencart精简checkout购物流程
  14. 基于SpringBoot的项目管理后台
  15. Nginx.conf配置文件参数说明与优化
  16. docker 进入容器的mongodb
  17. JVM java垃圾回收机制
  18. pycharm中conda环境部署
  19. Postman中使用post方式调用接口
  20. POJ 1328&amp;&amp;2109&amp;&amp;2586

热门文章

  1. linux c 获取网卡状态(UP or DOWN)
  2. Android代码实现控件闪烁效果
  3. C#创建一个Window服务
  4. Rest API By JAX-RS 实现接口发布
  5. Visual Studio提示“无法启动IIS Express Web服务器”或者“无法连接Web服务器IIS Express ”的解决方法
  6. CSDN开源夏令营 百度数据可视化实践 ECharts(4)
  7. python语言 buffer类型数据的使用 &#39;ascii&#39; codec can&#39;t decode byte 0xe5 问题的解决
  8. c++ about SLL(Static-Link Library) and DLL(Dynamic-Link Library)
  9. Shallow Heap &amp; Retained Heap
  10. 算法之动态规划(最长递增子序列——LIS)