Cupacabra Posted November 15, 2019 Posted November 15, 2019 When i send from page "/a" an ajax post request to page "/b" than it recive it on the chrome browser. On firefox, edge, or other mobile browsers it doesn't work. It return an 404 message. Page "/b" is a simple page with a template "b" which doesn't have any fields. What's wrong? Can a page reached only by get request? I want to process received data in an empty template. But this sould be called by ajax post request.
Cupacabra Posted November 15, 2019 Author Posted November 15, 2019 Here what i mean: // page "/a" template a.php... <form method="POST" action="<?=$pages->get('/submitmail/')->url;?>" id="contactMessage"> <h4>Form....</h4> <input name="name" placeholder="Name" type="text" required> <textarea name="comments" placeholder="Comment" rows="5" required></textarea><br> <button type="submit" id="btnSend">Send</button> </form> <script> $(document).on('submit', '#contactMessage', function(ev) { ev.preventDefault(); let form = $(this); let formData = form.serializeArray(); $('#btnSend').prop('disabled', true); $('#btnSend').html('<i class="fa fa-spinner fa-spin"></i>please wait...wathever..'); $.ajax({ method: form.attr('method'), url: form.attr('action'), data: formData }).done(function( msg ) { alert("it works..."); document.querySelector('#contactMessage').reset(); }).fail(function() { alert("Error!"); }).always(function() { $('#btnSend').prop('disabled', false); $('#btnSend').html('Send'); }); }); </script> // page "/b" template b.php... <?php if ($config->ajax) { $name = $_POST['name']; $comments = $_POST['comments']; // do anything with received data.... }
Zeka Posted November 15, 2019 Posted November 15, 2019 @Cupacabra Is there template file for the 'b' template?
rick Posted November 16, 2019 Posted November 16, 2019 @Cupacabra, It looks as though your form action (referenced in your ajax url) is not pointing to your b.php template so it is not being called.
Robin S Posted November 16, 2019 Posted November 16, 2019 6 hours ago, Cupacabra said: When i send from page "/a" an ajax post request to page "/b" than it recive it on the chrome browser. On firefox, edge, or other mobile browsers it doesn't work. It return an 404 message. It's unlikely the browsers themselves are making the difference here. Probably you are logged into the PW admin in Chrome but not in the other browsers. So your problem is due to some access restriction on page/template "b". 1
Cupacabra Posted November 16, 2019 Author Posted November 16, 2019 16 hours ago, Zeka said: @Cupacabra Is there template file for the 'b' template? yes. action="<?=$pages->get('/b/')->url;?>"
Cupacabra Posted November 16, 2019 Author Posted November 16, 2019 Now it works, the page was unpublished. ? Thanks.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now