Last active
August 29, 2015 14:17
-
-
Save songfei1983/1198937f83f42c50bef2 to your computer and use it in GitHub Desktop.
Play Framework 2.3.x Ajax通信 ref: http://qiita.com/songfei1983/items/b3540794b0664e089776
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This action is used to serve Home page of the application | |
* | |
* @return | |
*/ | |
def index = Action { implicit request => | |
Ok(views.html.index("Your new application is ready.")) | |
} | |
/** | |
* This action is used to handle Ajax request | |
* | |
* @return | |
*/ | |
def ajaxCall = Action { implicit request => | |
Ok("Ajax Call!") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
ajaxCall(); | |
}); | |
var ajaxCall = function() { | |
var ajaxCallBack = { | |
success : onSuccess, | |
error : onError | |
} | |
jsRoutes.controllers.Application.ajaxCall().ajax(ajaxCallBack); | |
}; | |
var onSuccess = function(data) { | |
alert(data); | |
} | |
var onError = function(error) { | |
alert(error); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(message: String)(implicit req: RequestHeader) | |
@main("Welcome to Play") { | |
@message | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(title: String)(content: Html)(implicit req: RequestHeader) | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>@title</title> | |
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> | |
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")"> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<!-- Embedded Javascript router --> | |
@helper.javascriptRouter("jsRoutes")( | |
routes.javascript.Application.index, | |
routes.javascript.Application.ajaxCall | |
) | |
<script src="@routes.Assets.at("javascripts/app.js")" type="text/javascript"></script> | |
</head> | |
<body> | |
@content | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /ajax-call controllers.Application.ajaxCall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment