How can I do something or call back-end after upload a file
I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.
Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.
<portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>
<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>
<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>
Here is the ajax part
function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}
$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});
function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}
Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?
I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.
if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());
}
html ajax portlet
add a comment |
I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.
Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.
<portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>
<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>
<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>
Here is the ajax part
function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}
$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});
function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}
Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?
I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.
if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());
}
html ajax portlet
how do you construct yoururlForAjax
?
– Olaf Kock
Feb 11 at 9:05
add a comment |
I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.
Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.
<portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>
<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>
<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>
Here is the ajax part
function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}
$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});
function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}
Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?
I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.
if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());
}
html ajax portlet
I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.
Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.
<portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>
<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>
<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>
Here is the ajax part
function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}
$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});
function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}
Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?
I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.
if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());
}
html ajax portlet
html ajax portlet
edited Jan 3 at 2:33
summer hkg
asked Jan 3 at 2:23
summer hkgsummer hkg
155
155
how do you construct yoururlForAjax
?
– Olaf Kock
Feb 11 at 9:05
add a comment |
how do you construct yoururlForAjax
?
– Olaf Kock
Feb 11 at 9:05
how do you construct your
urlForAjax
?– Olaf Kock
Feb 11 at 9:05
how do you construct your
urlForAjax
?– Olaf Kock
Feb 11 at 9:05
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015562%2fhow-can-i-do-something-or-call-back-end-after-upload-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015562%2fhow-can-i-do-something-or-call-back-end-after-upload-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
how do you construct your
urlForAjax
?– Olaf Kock
Feb 11 at 9:05