窗体打开在表单提交后不起作用

时间:2015-05-13 17:38:23

标签: php jquery

我有以下函数将值提交到mysql数据库。 php ajax调用工作正常。但是在插入函数之后,它不会执行与window.open相关的代码,它应该转到index.html页面。

function sendval(){
var tosubmit = validateForm();
if(tosubmit){
    showprog();

    // now create the json string to insert in the database
   var myData = {};
   myData.EmpName=localStorage.getItem("username");
   myData.LeaveType = $( "#leavetype option:selected" ).text();
   myData.LeaveStart = $('#txtFromDate').val();
   myData.LeaveEnd = $('#txtToDate').val();
   myData.ContactNum = $('#contactnum').val();
   myData.Comments = $('#Comments').val();
   myData.UsrMail = localStorage.getItem("usermail");
   myData.SupMail = localStorage.getItem("supmail");
   myData.Status = 'Submit';

    var myjson = JSON.stringify(myData);
    $.ajaxSetup( { "async": false } );
    $.ajax({
    method: "POST",
    url: "submitleave.php",
    data: {"points": myjson}
    })
    .done(function( msg ) {
        if(msg == 'Success') {
            alert("Submission successful");
        } else {
            alert("Could not sumbit - try again");
        }
        $.ajaxSetup( { "async": true } );   
        window.open("index.html","_self");
    }); 
  } else {
        alert("Please enter valid values before submitting the form");
  }

}

我尝试了几次迭代,但似乎没有得到错误。

其他一些功能也不起作用。

<header>XXXXX<br>
<br><input type="button" value="Logoff" id="logoff">
</header>

$('#logoff').click(function(){
   localStorage.clear();
   window.open("index.html","_self");
});

此致

0 个答案:

没有答案