zoukankan      html  css  js  c++  java
  • jQuery实现异步请求

    1:jQuery语法

    $(function(){
    	    $('#searchbtn').click(function(){
    		  
    		   $.ajax({
    			  type: "GET" ,
    			  url:"JSONsever.php?number=" + $('#keyword').val(),
    			  dataType :"json",
    			  success : function(data){
    				  if(data.success)
    				  {
    					  $('#search_result').html(data.msg)
    					  }
    				 else{
    					  $('#search_result').html("error" + data.msg);
    					 }	  
    
    				  },
    			 error : function(jqXHR){
    				 alert("发生错误"+ jqXHR.status)//404错误代码
    				 }
    			  })
    		  
    		  });//GET
    		  
    		   $('#savebtn').click(function(){
    		  
    		   $.ajax({
    			  type: "POST" ,
    			  url:"JSONsever.php?",
    			  data:{
    				   //JS对象JSON格式
    				   name : $('#staffName').val(),
    				   number : $('#staffNumber').val(),
    				   sex : $('#staffSex').val(),
    				   job : $('#staffJob').val(),
    				  
    				  },
    			  dataType :"json",
    			  sucess : function(data){
    				  if(data.success)
    				  {
    					  $('create_result').html(data.msg);
    					  }
    				 else{
    					  $('create_result').html("error" + data.msg);
    					 }	  
    
    				  },
    			 error : function(jqXHR){
    				 alert("发生错误"+ jqXHR.status)//404错误代码
    				 }
    			  })
    		  
    		  });//POST
    		  
    		  
    		  
    		  
    	  })
    

      

  • 相关阅读:
    1489 蜥蜴和地下室
    1521 一维战舰
    1596 搬货物
    1873 初中的算术
    CF-799B
    101 pick me up~
    落叶归根
    P1149 火柴棒等式
    P1540 机器翻译
    图论学习十之Sparse table
  • 原文地址:https://www.cnblogs.com/love-life-insist/p/9063808.html
Copyright © 2011-2022 走看看