I have read many questions/anwsers in the site regarding this issue and not sure any one of them can solve my problem. Below is how my application supposed to work:
I don't think the solutions using iframe, Window.location.href, or using html form will satisfy my requirements. Please let me know if there is any solution for my problem. Any help is greatly appreciated.
-Tam
As you writed it in your question title, i suggeste that you used a bit of javascript, either JQuery or prototype can do the job.
Since I know more about this last one, i will give some piece of code
here is the process I understand for your case.
First your server send a page with a form. Then the user select a file and click the send button, the page does not reload and use Ajax to do the job then JQuery get the data and send it to your server via Ajax ( request();
) then The server send back the results, and you can display it displayFilesList();
your_form_id
is your form id
submitForm
is the name of the function called when your form will be submitted
displayFilesList
will be the function called when your server will send back the results this function also expect you to send back the results in a json format
$('#your_form_id').submit(submitForm);
function submitForm()
{
var data = $('#your_form_id').serializeArray();
//Code to remove the send button here
//Code to insert a loading.gif
request("/your/url", data, displayFilesList);
return false;
}
function displayFilesList(jsonResult)
{
var data = jQuery.parseJSON(jsonResult);
//Code to display the files list here
//
}
function request(url, paramPost, successCallback, errorCallback)
{
if ((typeof successCallback == 'undefined') || (successCallback == null))
successCallback = dispSuccess;
if ((typeof errorCallback == 'undefined') || (errorCallback == null))
errorCallback = dispError;
var AjaxUrl = url;
$.ajax({
type: "POST",
url: AjaxUrl,
data: paramPost
}
).done( function(msg)
{
successCallback(msg);
}
).fail( function(jqXHR, textStatus, errorThrown)
{
errorCallback(jqXHR, textStatus, errorThrown);
}
);
}
function dispError(jqXHR, textStatus, errorThrown)
{
alert(jqXHR.responseText);
}
function dispSuccess(html)
{
alert(html);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.