How to do the following:
I want to have a link [upload image] which pop ups modal form, and when user populates it, the form is processed. (The question is not about uploading, this may be a contact form or anything).
My problem is, how to display the form a开发者_JAVA百科nd server side validation messages when validation fails.
I have found this tutorial: http://www.whitewashing.de/blog/articles/92, but it seems quite old.
Simple JQuery and Ajax :
$("#upvoteButton").live('click', function(){
postData="data="+value; /* Data that you may want to pass to your script */
$.ajax({
type: "GET",
url: "yourSecript.php",
async: true, /* If set to non-async, browser shows page as "Loading.."*/
cache: false,
data: postData,
success: function(data){
}
});
return false;
});
So the form should be processed right after user populates it? You don't want to wait until the user submits the form? Please elaborate.
Popping up can be accomplished easily. Have the form on the page from the start but hide it with CSS, for example like this:
.hidden-form {
height: 0;
text-indent: -999em;
}
Then, you can use click event to make the form appear:
$('#popup-link').click(function() {
$('#form').removeClass('hidden-form');
});
Displaying error messages is quite easy as well. Have a separate page that will process the form and print error messages if something goes wrong and success message when everything goes alright. Make an AJAX request with POST method of that page and just print the HTML output returned by the page on top of the form.
Show us some of your code (form and the server side processing page) for more specific help.
What I've been looking for are: ajaxLink()
, contextSwitch()
and ajaxContext
.
精彩评论