Problems with redirect on contact form

后端 未结 2 945
余生分开走
余生分开走 2021-01-29 06:57

I cant figure out why this wont redirect when everything looks in place.

I have used Location /path but just doesn\'t move from the main page.

Email sends and fo

相关标签:
2条回答
  • 2021-01-29 07:28

    php

    if (mail($to, $subject, $message, $headers)) {
        echo $redirect_thankyou; 
        die(); 
    } 
    else 
    { 
        echo $redirect_error"; 
        die(); 
    } 
    

    javascript

    $.post("hero-form.php", $("#register-form").serialize(),function(result){
        if(result){
           location.replace(result);
           $('#hero-success-notification').addClass('show-up');
           $('#hero-submit').addClass('disabled');
        }
    });
    
    0 讨论(0)
  • 2021-01-29 07:44

    The problem is your php header redirect:

    header("Location: $redirect_thankyou"); 
    

    This causes the browser to load the redirected page in your ajax call:

    $.post("hero-form.php", $("#register-form").serialize(),function(result){
    

    So result will contain the html contents of the page you have redirect to and not just the word sent.

    You need to remove the header() redirects in php and instead send the content back that your ajax call in jQuery is expecting. Json would be better suited for this, but a single string should work as well.

    0 讨论(0)
提交回复
热议问题