Nisha Sharma
Nisha Sharma

Reputation: 255

Getting 404 error when calling php file in react js

I have created a simple contact form and using php via ajax. I passed the url like: /api/index.php where api folder is in the root folder.

$.ajax({ url: "/api/index.php", type: 'POST', data: { 'form_email': this.state.contactEmail, 'form_msg': this.state.contactMessage },

But when I'm submitting form getting 404 error. "Cannot POST /api/index.php"

I need help to call php file via ajax or other method to submit form.

Upvotes: 0

Views: 298

Answers (1)

Hossein Safari
Hossein Safari

Reputation: 11

I think you need to change the type: 'POST' to method: 'POST'

Upvotes: 1

Related Questions