点击提交按钮后如何关闭灯箱表格?

问题描述:

i have a light box form ( and have page in the background ).i want to close the light box and stay on that page after clicking on submit button .but its redirecting to another page ( php database connection page ) after clicked on submit button.need help.i want to know how to close light box and stay on that page.thank you!

我有一个灯箱形式(并在后台有页面)。我想关闭灯箱并留下 单击提交按钮后,在该页面上。但是在点击提交按钮后,它会重定向到另一个页面(php数据库连接页面)。需要帮助。我想知道如何关闭灯箱并留在那个页面上。谢谢你! p> div>

Add an event listener to the form that handles the form request and then return false from that handler and the page won't refresh. Because we don't know which lightbox you are using we can't exactly tell you how to remove it... but if you're using jQuery you could use something like:

$("#lightbox-id").hide();

or

$("#lightbox-id").remove();

Use JavaScript to submit the form within the lightbox & close the lightbox.

function send_form ( )
{
ajax = new XMLHttpRequest;
if (!ajax) return false;

ajax.open('POST', '/index/send_form/'); //your post url should be here
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

var field0= document.getElementById('submit').value;
var field1 = document.getElementById('message').value; //you should modify these fields according to your form 

ajax.send('sub=' + submit + '&message=' + content);
//then post url becomes something like: www.example.com/index/send_form/?sub=submit&message=this

//then close the lightbox in here
}

and for the html part remove action attribute and call this function in onsubmit event.