Jump to content

Assigning PHP file to JQuery Ajax POST Request Results in 404 Page Not Found


bytesource
 Share

Recommended Posts

Hi, 

I am trying to handle a form submit using the JQuery ajax function. However, the following always results in a 404 page not found error:

<?php
    $subscribe = $config->paths->templates . 'includes/partials/' . 'subscribe.php';
?>

[...]

$.ajax({
      url: "<?php echo $subscribe ?>", 
      data: $('#subscribe').serialize(),
      type: 'POST',

[...]
 
After submitting the form, I always get the following error in Google Chrome's page inspector:
 
Including PHP files into template files has not caused any problems before, but here something seems to be different, and I suspect it has to do with how POST requests are handled.
 
Cheers, 
 
Stefan
 
 
Link to comment
Share on other sites

I think that it is not possible to directly access php files in the "templates" directory (because if everyone could do it it would be a big insecurity).

Of course you can include them via PHP because this get's rendered before the page is returned to the user. But jQuery/Javascript acts more like a real user. And for them everything (except images, javascript files, stylesheets, etc.) in /site/ and in /wire/ is locked.

What you have to do:

Create a template in the backend called e.g. "subscribe". Then create a page using this template e.g. named "subscribe", too. You now can access this page via http://localhost:8080/home/sovonex/Programs/rubystack-2.0.0-12/apps/processwire/htdocs/subscribe/ or something similar. That's the page you should point your post request on.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...