You are not logged in.
Pages: 1
Hi All,
I have an MVC server currently working well, however I want to be able to call services that don't return a page.
For example I have a page where an admin can reset a users password just by clicking a button. The page doesn't need to change (and I don't want it to change), however I may want to display a "dialog" to say that the password reset has been successful.
So my questions are:
1. Can I do this within the MVC framework?
2. If so, how?
3. If not, what are my other options?
Thanks in advance.
Joker.
Offline
The MVC feature is mostly server-side.
So for such case, the default way is to return a page.
I see two options (but there may be other ways):
1. Add a REST AJAX call.
In the Mustache template, add some JavaScript to display the dialog box.
Then define an interface-based service, in addition to the MVC server, to handle the classical AJAX request.
2. Redirect to a HTML sub-frame.
In the Mustache template, add some JavaScript to display the dialog box as a HTML sub-frame.
Then fill the dialog frame from a dedicated page on the MVC server.
Perhaps the option 2 is more easy to setup.
Online
Thanks ab. I might try option 2 and see how I go.
Offline
Actually I found a better way to do this using the "/json" tag at the end of the URL. This means I can call the function without creating a new server and still use the authentication/cookie data as I would for normal page calls. Here is a quick example of the js function I call :
function resetpassword(client_id, user_name){
$.post("/admin/resetpassword/json",
{
ClientID: client_id,
UserName: user_name
},
function(data,status){
if (data.ResetPasswordResult.Success)
{
document.getElementById("dialog_title").innerHTML = "Reset Password";
document.getElementById("dialog_content").innerHTML = "Password reset successful";
$("#ModalDialog").modal();
}
else
{
document.getElementById("dialog_title").innerHTML = "Reset Password FAILED!";
document.getElementById("dialog_content").innerHTML = data.ResetPasswordResult.ErrMsg;
$("#ModalDialog").modal();
}
})
.fail(function() {
document.getElementById("dialog_title").innerHTML = "Reset Password FAILED!";
document.getElementById("dialog_content").innerHTML = "Unable to access server";
$("#ModalDialog").modal();
})
;
}
Offline
Yes, this is a nice trick!
Reusing the very same cookie content for authentication and safety is definitively a plus.
And, on the server side, you don't need to define additional methods or interfaces services.
You got a brilliant idea!
The /json suffix was meant for debugging/testing, but in fact it could be used for actual REST service implementation.
Thanks for sharing.
Online
Hello,
So on the server-side function "/admin/resetpassword", instead of returning a HTML page, you return a JSON string, right?
Thanks.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Pages: 1