1. JSP Code
This file contains 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
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<liferay-portlet:resourceURL var="sampleUrl" /> | |
<input type="button" value="Ajax Call" onclick="ajaxMethod('${sampleUrl}');" /> | |
<script> | |
function ajaxMethod(sampleUrl){ | |
$.ajax({ | |
type: 'GET', | |
url: sampleUrl, | |
cache:false, | |
async:true, | |
error: function(){ | |
alert('error'); | |
}, | |
dataType : "html", | |
data :{ | |
name:"hello123" | |
}, | |
success: function(htmlData) { | |
alert('response : ' + htmlData); | |
}, | |
complete: function(){ | |
} | |
}); | |
} | |
</script> |
This file contains 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
@ResourceMapping | |
public void serveResource(ResourceRequest request, ResourceResponse response) | |
{ | |
System.out.println("method called"); | |
try { | |
response.getWriter().write("<h1>Hello</h1>"); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} |
Hi!
ReplyDeleteAlso you can receive data in serveResource?
Can I receive name:"hello123" ???
I have tried : String name = ParamUtil.getString(request, "name");
But is not working ...
Any suggestions?
Thanks!