ajax +jquery 基本

lcc發表於2021-09-09

ajax格式,(key:value,)value值用單引號括起來

$.ajax({

type:,      //'post','get'

url:,        //action的路徑

data:,    //傳到後臺的引數,多個引數的連線符為'&'

success:function(msg){}//對返回的JSP頁面或結果進行處理

});

1)jsp:


       
 

   --%>
                        

 

 

2)Javascript:

data的值表示把頁面的值傳到後臺(/GetSN.action),多個引數的連線符為'&'

執行成功後把結果放到一個JSP頁面(ajaxSN.jsp),透過 success:function(msg),放到ID為'div_sn'

function getsn(){  
              document.getElementById("div_sn").style.display="block";
              var sn = $('#sn').val();
              var product=$('#product').val();
              if(sn.length>5){    
                    $.ajax({
                        type:'post',
                        /GetSN.action'">url:'/GetSN.action',
                        timeout:2000,
                        data:'sn='+$('#sn').val() +'&product='+$('#product').val(),
                        success:function(msg){
                          $("#div_sn").html(msg);
                        }
                    });
                  }
            }

 

3)ajaxSN.jsp

 


    


        
        JSP Page
        
    
    
        

        
        

    

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/2331/viewspace-2814345/,如需轉載,請註明出處,否則將追究法律責任。

相關文章