1

I use fat free PHP framework.

PHP:

 F3::route('POST /vote', function(){
            global $twig;
            if(isset($_GET['studentKey'])){
                $studentKey = $_GET['studentKey'];
                //выборка id студента
                $SELECT_student_Id = "SELECT id FROM identification WHERE studentKey = '$studentKey'";
                DB::sql($SELECT_student_Id);
                $studentId = F3::get('DB->result');
                //выборка id преподавателя
                $SELECT_teacher_Id = "SELECT idPrep FROM kbinding WHERE idStudent =". $studentId[0]['id'];
                DB::sql($SELECT_teacher_Id);
                $teacherId = F3::get('DB->result');

                echo $twig->render('vote.html', array('ids' => $studentId[0]['id'],
                         'teacherId' => $teacherId[0]['idPrep']));
            }else{

                echo $twig->render('404.html', array('error' => 'Ошибка'));
            }
        });

JavaScript:

$(document).ready(function(){    
    $('#sendData').click(function(){
        $.ajax({type: "POST", url: "engine.php", data: some_data, 
            success:function(){
                ***location.reload();***
            },
            error: function(){
                alert("Error");
            } 
        });
    });
});

And I cant refresh the page, because it is a post method. How can I use Post method and refresh this page without problems??

  • 3
    If you want to refresh after POST, don't use AJAX, use SUBMIT. – Diodeus - James MacFarlane Mar 26 '13 at 19:00
  • You certainly can refresh a page with JavaScript: http://stackoverflow.com/q/5404839/328193 – David Mar 26 '13 at 19:01
  • I am exactly do it! In my java script file I have location.reload(); but I have an error Method Not Allowed GET request is not allowed for the URL /vote. This is a problem... how refresh the page. F3::route('POST /vote', functio... this page creates via post method as you see.. if it will be a get method, it will work –  Mar 27 '13 at 02:00
  • 2
    You have to add a GET route for /vote which displays the same content like the POST route after a successfull submit. – sascha Apr 02 '13 at 06:47
  • 1
    Thank you!) I have already done it!) I just forget to close a question!:) –  Apr 02 '13 at 16:29

2 Answers2

0

My solution is next:

  1. Create form, add method 'post'
  2. Create temp page, which receives values from form.

    2.1 Store this value in session

    2.2 After this, redirect to another page

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
0

And you can use the reroute() method for the redirection.

Crossmax
  • 58
  • 1
  • 7