Ajax calls within Javascript files not working properly
-
Hi everyone
I’m having a little trouble with my ajax calls here.
The site I’m working on never used to be on wordpress but since I ported it over I have come across a problem regarding the way my contact form works. First of all, there is a script called contact.js which has a function validating the fields in the form, and if successful it should make an ajax call to a file called ajax.php.
Below is how it was implemented before:
$.ajax({ type: "POST", url: "ajax.php", data: { trigger: "contactrequest",message: message,name: name,email: email,subject: subject,type: type }, success: function(msg){ alert( msg ); } });
This is using the jQuery method. Unfortunately the file cannot be found by wordpress as there is no absolute path. I don’t want to hard-code it as I will be porting the site to a different server when done so there must be a way of somehow making sure it points in the right direction? The ajax.php file is in my theme root folder, and the contact.js which calls it is in a subfolder called “js”.
Any help in this matter is greatly appreciated as this is an important part of the site and needs to be implemented in this way.
Thank you!
Michael
- The topic ‘Ajax calls within Javascript files not working properly’ is closed to new replies.