zoukankan      html  css  js  c++  java
  • jquery-ajax的用法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    	<title>jq-1</title>
    	<style>
    	#info{ border: 1px solid red;  100px;}
    	</style>
    	<script src="http://www.w3school.com.cn/jquery/jquery.js"></script>
    	<script>
    	$(function (){
    		//alert($("#info").html());
    		$("#info").click(function (){
    			$.ajax({
    				url:"./ajax1.txt",	//url请求的地址
    				beforeSend:beforeSend2,	//发送之前执行的操作
    				error:error2,	//发生错误时候执行
    				success:success2,	//成功时执行
    				datatype: 'text'	//接受从服务器返回的数据类型	xml、html、script、json、jsonp、text.
    			});			
    		});
    		function beforeSend2(){
    			alert("这里是beforeSend");
    		}
    		function error2(){
    			alert("出错的error在这里");
    		}
    		function success2(data){
    			alert(data);
    			$("#info2").html(data);
    		}
    	});
    	</script>
    </head>
    <body>
    	<div id="info">info</div>
    	<div id="info2"></div>
    </body>
    </html>
    

      


    • dataType的类型

    • ajax是向服务器请求数据
    • No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.  跨域
      •   在服务器上运行ajax的请求。
  • 相关阅读:
    web框架学习
    css上
    数据库
    线程
    反射以及部分内置方法
    排序函数sort() 和sorted() 之介绍
    类的绑定方法
    继承
    面向对象和类
    混淆矩阵、准确率、召回率
  • 原文地址:https://www.cnblogs.com/xy404/p/3691040.html
Copyright © 2011-2022 走看看