开发者_开发知识库That is ,I want to keep the original page while POST a form.
You could simply use the target
attribute of the form:
<form method="post" target="_blank" action="...">
Note that even though this will work in all major browsers, it is deprecated and your page will not validate as per W3C standards.
There are two ways you can accomplish this. If the page can be reloaded, just post the form to the page you are currently on. If you want to submit the form with AJAX (no page reload), then a javascript library such as jQuery is recommended (to save you the trouble of manually constructing an XHR request. Here is an example of ajax with jQuery:
window.onload = function(){
$('.image').click(function(){
var image_id = $(this).attr('id');
$.ajax({
type: "POST",
url: "/ajaxpage.php",
data: {
id:image_id
}
success: function(data){
alert(data);
},
failure: function(){
alert('failed');
}
});
});
}
From the page you call here, you can echo a response that will be handled by the ajax success handler.
精彩评论