大佬教程收集整理的这篇文章主要介绍了jquery – 在grails中从gsp页面进行ajax调用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<%@ page contentType="text/html;charset=UTF-8" %> <html> <head> <title>Ajax First Example</title> <g:javascript plugin="jquery" library="jquery" src="jquery/jquery-1.7.2.js"/> <script> function callAjax(){ $.ajax({ url: "returnMe",type:"post",dataType: 'json',// data:{ids:JSON.stringify(idList),option:option,id:id} success: function() { alert(1) } }); } </script> </head> <body> <form name='myForm'> <input type="submit" value="Call Ajax Function" onclick="callAjax()"> </form> </body> </html>
这是我的控制器操作>>>
def returnMe = { String msg = 'sdfsdf' render msg as JSON }
onclick="callAjax() return false;">
或者这个:
function callAjax(e){ //<-------pass the event e.preventDefault(); // <-----add this to prevent the default behavior $.ajax({ ..... }); }
您要求的完整ajax呼叫:
function callAjax(){ $.ajax({ url: "returnMe",// data:{ids:JSON.stringify(idList),id:id} success: function(data) { console.log(data); //<-----this logs the data in browser's console },error: function(xhr){ alert(xhr.responseText); //<----when no data alert the err msg } }); }
以上是大佬教程为你收集整理的jquery – 在grails中从gsp页面进行ajax调用全部内容,希望文章能够帮你解决jquery – 在grails中从gsp页面进行ajax调用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。