`
heng_aa
  • 浏览: 3767 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Jquery后台调用(更新中)

阅读更多

一种方法:

1.收引入jquery.js:

<script type="text/javascript" src="js/jquery-1.4.js"></script>

2.页面:

        <form action="demo.do" method="post" id="demoForm">   
            ajax测试   
         <input type="text" id="val" />   
            <input type="text" id="result"/>   
            <input type="button" id="btn" value="ajax" onclick="getData()"/>   
        </form>  

3.js:

 function getData(){
  	$.ajax({
		type: 'post',
  		url: '',           //调用的地址.
  		data: {'val': $("#val").val(), 'name':'value'},     //传过去的参数.
  		success: function(result){
  			$("#result").val(result);        //返回的结果.
  		}
  	});
  }

  

4.后台代码:

response.getOutputStream().print("test");

 

其它方法:

1、$.getJSON(url,  null,  function(data){} )。

 

 

 

 

 

表单异步提交:

 

 

$(document).ready(function(){
       $('#myform').submit(function(){
           jQuery.ajax({
               	      url: "url",   // 提交的页面
               data: $('#myform').serialize(), // 从表单中获取数据
               type: "post",                   // 设置请求类型为"POST",默认为"GET"
                      //dataType: "json",
                      success: function(data) {
                          //alert('here');
               	      }
           });
           return false;
       });
   });

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics