Javascript 使用'时重定向;onclick';使用输入元素

Javascript 使用'时重定向;onclick';使用输入元素,javascript,php,html,Javascript,Php,Html,我的HTML是- <input type="submit" onclick="javascript:agreeprint();" value="Proceed"> 我的JavaScript函数是- <script type="text/javascript"> function agreeprint() { if($("#company").val()==''||$("#office_address").val()=='')

我的HTML是-

<input type="submit" onclick="javascript:agreeprint();" value="Proceed">

我的JavaScript函数是-

<script type="text/javascript">
    function agreeprint()
    {
        if($("#company").val()==''||$("#office_address").val()=='')
        {
            alert('<?php echo $this->translate('Please enter the empty field values'); ?>');
            return false;
        }
        else
        {
            var companyval  = $("#company").val();
            var officeaddrval = $("#office_address").val();
            $.ajax({
                type: "POST",
                url: "/index/agreement",
                data: $( "form" ).serialize(),
                success: function(msg){
                    if(msg.substr(0,9)=='contratt_')
                    location.href = '/filename/'+msg;
                }
            }); 
        }

        window.location = "/index";   //The redirection is not working
    }
</script>

函数agreeprint()
{
如果($(“#公司”).val()=''|$(“#办公室地址”).val()='')
{
警报(“”);
返回false;
}
其他的
{
var companyval=$(“#company”).val();
var officeaddrval=$(“#办公室地址”).val();
$.ajax({
类型:“POST”,
url:“/index/agreement”,
数据:$(“表单”).serialize(),
成功:功能(msg){
如果(msg.substr(0,9)='contratt_u3;')
location.href='/filename/'+msg;
}
}); 
}
window.location=“/index”//重定向不起作用
}

函数完成后,重定向过程不会发生。我做错了什么?

重定向没有问题,因为我运行了代码的重定向部分

<script type="text/javascript">
function agreeprint()
{
    window.location = "/index";   //The redirection is not working
}
</script>

<input type="submit" onclick="javascript:agreeprint();" value="Proceed">

函数agreeprint()
{
window.location=“/index”//重定向不起作用
}
而且它工作得很好。在重定向之前,javascript一定有问题:

if($("#company").val()==''||$("#office_address").val()=='')
    {
        alert('<?php echo $this->translate('Please enter the empty field values'); ?>');
        return false;
    }
    else
    {
        var companyval  = $("#company").val();
        var officeaddrval = $("#office_address").val();
        $.ajax({
            type: "POST",
            url: "/index/agreement",
            data: $( "form" ).serialize(),
            success: function(msg){
                if(msg.substr(0,9)=='contratt_')
                location.href = '/filename/'+msg;
            }
        }); 
    }
if($(“#公司”).val()=''办公室地址($).val()='')
{
警报(“”);
返回false;
}
其他的
{
var companyval=$(“#company”).val();
var officeaddrval=$(“#办公室地址”).val();
$.ajax({
类型:“POST”,
url:“/index/agreement”,
数据:$(“表单”).serialize(),
成功:功能(msg){
如果(msg.substr(0,9)='contratt_u3;')
location.href='/filename/'+msg;
}
}); 
}
从我运行代码时遇到的错误判断,我猜您的AJAX有问题,因为我在运行代码时遇到了一个奇怪的POST错误,并且我还发现缺少一个“)”但我不熟悉AJAX,所以我只是猜测

SyntaxError:在参数列表之后缺少)

我希望这有帮助,
Conor.

ajax成功后,msg的
中有什么内容?这是一个供合同下载的文件名。。我需要下载过程后的url应该重定向,这是我需要它。我在javascirpt方面很差..试试window.location.href=@ramp应该没关系。查看并记录消息,然后再检查其值。PDF是什么样子的?