Springmvc ajax jump learning Notes

Source: Internet
Author: User

First

The returned value is Map <String, Object>.

Controller writing

/**
* Error correction
* @ Author admin
  *
*/
 
@ RequestMapping (value = "/checkQuestion. php ")
@ ResponseBody
Public Map <String, Object> checkQuestion (Long titleId ){
 
Map <String, Object> map = new HashMap <String, Object> ();
Map. put ("ceshi", "error correction passed back in the background ");
System. out. println (map. toString ());
Return map;
}

Page 1


$ ('. Other1'). click (function (){
$. Ajax ({
Url: '/vote/checkQuestion. Php ',
Data: $ ('# form1'). serialize (), // your formid
Success: function (data ){
If (data! = Null ){
Alert ("error correction" + data. ceshi );
            
      }
   
    }
});
})
 
<Form id = "form1">
<Input type = "hidden" name = "titleId" value = "$ {question. id}">
 
</Form>
 

Second

The returned value is a json string.

/**
* Add To Favorites
* @ Author admin
  *
*/
 
@ RequestMapping (value = "/collectionQuestion. php", produces = "application/json; charset = utf-8 ")
@ ResponseBody
Public String collectionQuestion (){
JSONArray array = new JSONArray ();
JSONObject json = new JSONObject ();
Json. put ("ceshi", "back-end collection ");
Array. add (json );
System. out. println (array. toString ());
Return array. toString ();
}

Page description 2


$ ('. Other2'). click (function (){
 
$. Ajax ({
Url: '/vote/collectionQuestion. php? TitleId = '+ $ {question. id },
Success: function (data ){
If (data! = Null ){
Alert ("favorites" + data [0]. ceshi );
      }
    
    }
});
})

Related Article

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.