Wyświetlanie Loadera i funkcja before send

0

Nie wiem dlaczego to nie działa.

<?php
                                             
															
		(!isset($_GET['step'])) ? $_GET['step'] = 'form' : $_GET['step'] = $_GET['step'];
															
															
		switch($_GET['step']):

				case 'form':

?>
				   <style type="text/css">

.loader {
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: url('ajax-load.gif') 50% 50% no-repeat rgba(249,249,249,.8);

}
</style>
	<script type="text/javascript">
	        $(document).ready(function() {

                $('#submit').click(function() {

                    $.ajax({

                        type: "POST",

                        url: "index.php?step=save",

                        cache: 'false',

                        data: $("#form").serialize(),

                        beforeSend: function() {

                            $('.ajax').html('<img class="loader" />').show();

                        },

                        dataType: "html",

                        success: function(result) {

                            $("#error_message").html(result);

                            	$(".ajax").fadeOut("slow");

				  window.location.href = 'index.php?step=thx';

                        },
                        error: function(xhr, ajaxOptions, thrownError) {

      alert('Something went wrong. Please try again.');


                            	$(".ajax").fadeOut("slow");

                        }
                    });


                    return false;

                });

            });
	</script>



 <?php 

				  print "<form action=\"\" method=post id=form>";
				  print "<input type=\"text\" name=\"to\" />";
				  print "<input id=submit type=\"submit\" value=\"okkk\" /></form>";		

				  
print "<div class=\"ajax\"></div>";


				 exit();
				

				break;

				case 'save':

				print "save";

				break;

				default:
				header("location: " . $_SERVER['SCRIPT_NAME']);
				break;
				exit();
				endswitch;
                     

?>

Nie wiem tez co mam dac konkretnie do pola ACTION w formularzu. Ścieżkę do pliku z parametrem ? tyle ze w JS jest już ścieżka chyba że ja to źle robię.

0

Jednak nie dziala. Tzn nie zapisuje tresci do pliku.

<?php
                                             
															
															(!isset($_GET['step'])) ? $_GET['step'] = 'form' : $_GET['step'] = $_GET['step'];
															
															
															  switch($_GET['step']):

				case 'form':
print "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>";
            print "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js\"></script>";
			    ?>
				   <style type="text/css">

.loader {
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: url('ajax-load.gif') 50% 50% no-repeat rgba(249,249,249,.8);

}
</style>
	<script type="text/javascript">
	        $(document).ready(function() {

                $('#submit').click(function() {

                    $.ajax({

                        type: "POST",

                        url: "index.php?step=save",

                        cache: 'false',

                        data: $("#form").serialize(),

                        beforeSend: function() {

                            $('.ajax').html('<img class="loader" />').show();

                        },

                        dataType: "html",

                        success: function(result) {

                            $("#error_message").html(result);

                            	$(".ajax").fadeOut("slow");

				  window.location.href = 'index.php?step=thx';

                        },
                        error: function(xhr, ajaxOptions, thrownError) {

      alert('Something went wrong. Please try again.');


                            	$(".ajax").fadeOut("slow");

                        }
                    });


                    return false;

                });

            });
	</script>



				 <?php 

				
				
				  print "<form ACTION=\"\" method=post id=form>";
				  print "<input type=\"text\" name=\"to\" />";
				  print "<input id=submit type=\"submit\" value=\"okkk\" /></form>";		

				  
print "<div class=\"ajax\"> </div>";


				 exit();
				

				break;
				
				case 'save':
				
				$foo = fopen('1.txt','a+');
				fwrite($_POST['to'], $foo);
				fcloe($foo);
				
				break;

				case 'thx':

				print "saved";

				break;

				default:
				header("location: " . $_SERVER['SCRIPT_NAME']);
				break;
				exit();
				endswitch;
                     

?>

W kodzie js jest przekierowanie i to sie wykonuje. Loader dziala ale kod php juz nie. w kodzie js mam url: "index.php?step=save", ale to nie wykonuje sie.

1 użytkowników online, w tym zalogowanych: 0, gości: 1