The page uses the callback function functions (data) to handle the results returned by the background
A tag onclick event trigger
<a href = "javascript:void (0);" class= "btn btn-default" id = "Add" onclick = "return Addproduct (${s.id});" > Add seconds to Kill </a>
Front desk
Function addproduct (ID) { var mprice=document.getelementbyid ("Mprice_" +id) .value; var number=document.getelementbyid ("Number_" +id). value; var sid= document.getElementById ("Special.id") .value; if (mprice== "") { alert ("Please enter Special price" ); return false; }else if (number== "") { alert (" Please enter a special quantity ") return false; }else { //Focus here $.get (" ${ctx}/ Special/addproduct.action?specialvo.quantity= "+number+" &specialvo.memberprice= "+mprice+" &specialVo.id= "+id+" &special.id= "+sid, function (data) { if (data==" true ") { alert (" add success "); window.location.reload (); } }) /* window.location.href= "${ Ctx}/special/addproduct.action?specialvo.quantity= "+number+" &specialvo.memberprice= "+mprice+" & Specialvo.id= "+id+" &special.id= "+sid; */ } }
Background
public void addproduct () { printwriter out=null; try { system.out.println (Specialvo.getquantity ()); System.out.println (Specialvo.getmemberprice ()); system.out.println ( Specialvo.getid ()); system.out.println (Special.getid ()); httpservletresponse response= Servletactioncontext.getresponse (); out=response.getwriter (); Out.print (True); out.flush (); out.close (); } catch (exception e) { E.printstacktrace (); out.flush (); out.close (); out.println (0); } }
Struts configuration action requires no result
<action name= "addproduct" class= "specialaction" method= "addproduct" > </action>
Reference article:
http://bbs.csdn.net/topics/390470284
http://blog.csdn.net/xuzhuang2008/article/details/6928304
This article is from the "Nothing-skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1678174
Jquery Ajax does not refresh page commit action get return value