Ben poll.php standart bir form var:
<form method="POST" action="createpoll.php">
..blah...
</form>
Createpoll.php için kullanıcı, teslim tarihinde createpoll.php arama gibi bir şey önde olmadan formu işlemek için yine de var mı?
Bu teknoloji olarak adlandırılır AJAX. JavaScript kütüphaneleri yardımı ile onu kullanmak gerçekten çok kolay hale geldi. Sen JQuery veya Prototype kullanabilirsiniz. AJAX sunulması için arayın. Cevaplar bir sürü bu konuda vardır - yani, stackoverflow questions.
Exapmle için, JQuery yöntemi kullanılarak ajax() bu (JavaScript) gibi görünüyor:
$.ajax({
type: "GET", // method - Get or Post
url: "cart.php", // Url to send data
data: { addproduct: productIDVal, isAjax: 'true'}, // Parameters
success: function(theResponse) {
// code to operate with response, if the request was succesful.
// It can be string or array.
}
});
Lütfen formda Ajax kullanmak için harika, son derece kolay yolu burada bulunabilir: http://jquery.malsup.com/form/
This is a great tutorial that should help you get started: http://onlamp.com/pub/a/onlamp/2005/05/19/xmlhttprequest.html
Sen, JavaScript ile form gönderme yakalamak XMLHttpRequest (XHR) ile veri göndermek ve yanıt ayrıştırmak için ihtiyacımız olacak.
http://js.isite.net.au/snippets/form2obj izniyle
Ayrıca aynı sitede obj2query
fonksiyonu bulabilirsiniz.
<form action="submit.here" method="POST" onsubmit="submit_via_xhr( this.method,
this.action, obj2query( form2obj( this ) ), successFunction ); return false">
function form2obj(theForm) {
var rv = {};
if (typeof(theForm) == 'string')
theForm = document.getElementById(theForm);
if (theForm) {
for (var i = 0; i < theForm.elements.length; i++) {
var el = theForm.elements[i];
if (el.name) {
var pushValue = undefined;
if (
(el.tagName.toUpperCase() == 'INPUT'
&& el.type.match(/^text|hidden|password$/i))
|| el.tagName.toUpperCase() == 'TEXTAREA'
|| (el.type.match(/^CHECKBOX|RADIO$/i) && el.checked)
){
pushValue = el.value.length > 0 ? el.value : undefined;
}
else if (el.tagName.toUpperCase() == 'SELECT') {
if( el.multiple ) {
var pushValue = [];
for( var j = 0; j < el.options.length; j++ )
if( el.options[j].selected )
pushValue.push( el.options[j].value );
if( pushValue.length == 0 ) pushValue = undefined;
} else {
pushValue = el.options[el.selectedIndex].value;
}
}
if( pushValue != undefined ){
if(rv.hasOwnProperty( el.name ))
if( rv[el.name] instanceof Array ) {
rv[el.name] = rv[el.name].concat( pushValue );
}
else {
rv[el.name] = [].concat( rv[el.name], pushValue );
}
else {
rv[el.name] = el.value;
}
}
}
}
}
return rv;
}