1

My HTML is -

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

And my JavaScript function is -

<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>

After the function is finished the redirection process does not happened. What am I doing wrong?

8
  • 1
    What is in msg after ajax success? Commented Feb 5, 2015 at 12:04
  • Its a filename for the contract to download.. I need that after download process the url should redirect that's what i need it. I am poor in javascirpt.. Commented Feb 5, 2015 at 12:07
  • 1
    try window.location.href = <your_value> Commented Feb 5, 2015 at 12:08
  • @ramp It shouldn't matter. See this and this. Commented Feb 5, 2015 at 12:16
  • 1
    log the msg before you check it's value. What does /contractpdf look like? Commented Feb 5, 2015 at 12:16

1 Answer 1

1

There is nothing wrong with the redirection because I ran jun the redirection part of your code,

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

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

and it works perfectly. There must be something wrong with the javascript before the redirection:

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;
            }
        }); 
    }

Judging from the errors that I was getting when I ran the code I am guessing that there is a problem with your AJAX because I got a odd POST error when I ran the code and I also discovered that there is a missing ")" but I am not familiar with AJAX so I am just guessing,

SyntaxError: missing ) after argument list

I hope this helps, Conor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.