Jquery Ajax does not refresh page commit action get return value

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.