我有一个javascript确认框,如果用户点击OK,那么我想运行一个php脚本。不确定如何做到这一点。以下是确认框的javascript代码:
<script type="text/javascript">
function val_name()
{
var namePattern = /^[A-Za-z]{3,25}$/;
if( !namePattern.test(document.upload.fn.value))
alert("Enter valid first name");
if( !namePattern.test(document.upload.ln.value))
alert("Enter valid last name");
var x=document.forms["upload"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length)
{
alert("Not a valid e-mail address");
return false;
}
else if
(confirm("Are you sure you want to add this driver?")== true)
{
onClick = 'add_driver.php';
}
}
</script>
答案 0 :(得分:0)
这就是你要找的东西吗?
window.location.href='add_driver.php';
答案 1 :(得分:0)
window.location.href = 'add_driver.php';
这会将您带到页面,导致脚本运行。如果您不想访问该页面但只是想让它运行,请查看jQuery并使用其AJAX函数。
答案 2 :(得分:0)
调用add_driver.php的Ajax代码
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//here you can put some code to execute if the call to add_driver.php was ok
}
}
xmlhttp.open("GET","add_driver.php",true);
xmlhttp.send();
}