zoukankan      html  css  js  c++  java
  • jQuery get post 碎片(远程html)加载

    <!DOCTYPE html>
    <html>
    
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<script src="jquery-2.2.4.min.js"></script>
    		<script>
    			/*  get 和post 请求,就简单调用方法就行*/
    			$(window).load(function() {
    				$('#btn').on('click', function() {
    					$.get('http://localhost/myservice/jQueryAjax.php', {
    						'name': $('#inputID').val()
    					}, function(d) {
    						$('#spanID').text('结果是:' + d);
    					}).error(function(e){
    						console.log(e);
    					});
    				});
    
    			});
    		</script>
    	</head>
    
    	<body>
    		<input type="text" id="inputID" />
    		<br/>
    		<button id="btn">Send</button>
    		<span id="spanID"></span>
    	</body>
    
    </html>
    

      

    加载碎片

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<script src="jquery-2.2.4.min.js"></script>
    		<script>
    		
    			$(document).ready(function(){
    				//加载碎片,加载远程html元素,还能执行其中的JS方法
    				$('body').load('box.htm',function(a,status,c){
    					console.log(status);
    					test();
    				})
    				//加载另外的js文件
    				$.getScript('碎片加载中.js',function(){
    					//调用JS方法
    					loading();
    				});
    			});
    		</script>
    	</head>
    	<body>
    	</body>
    </html>
    

      

    box.htm

    <div style=" 100px;height: 100px;background: red;"></div>
    <script>
    function test(){
    	alert("test方法被执行了");
    }
    </script>
    

    碎片加载中.js

    function loading(){
    	alert('加载中...');
    }
    

      

  • 相关阅读:
    python_6
    python_day4
    python_day3
    python_day2
    python
    python入门
    jQuery之前端国际化jQuery.i18n.properties
    转载!网页中插入百度地图
    jQuery.validate 中文API
    Web移动端Fixed布局的解决方案
  • 原文地址:https://www.cnblogs.com/yqlog/p/5577269.html
Copyright © 2011-2022 走看看