jeudi 26 février 2015

Why do I get "POST http://ift.tt/1Bh4iH6 404 (Not Found)" when using Wordpress+Ajax?


Vote count:

0




It's the first time for me using ajax on WP. I am working on a simple contact form, and for some reason whenever I click submit I get an error:


on console:



POST http://ift.tt/1Bh4iH6 404 (Not Found)jquery.js?ver=1.11.1:4 m.ajaxTransport.sendjquery.js?ver=1.11.1:4 m.extend.ajaxmain.js:66 (anonymous function)jquery.js?ver=1.11.1:3 m.event.dispatchjquery.js?ver=1.11.1:3 m.event.add.r.handle


on chromes "Networks":



Remote Address:54.xxx.xx.xx:80
Request URL:http://ift.tt/1Bh4iH6
Request Method:POST
Status Code:404 Not Found
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:76
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:wp-settings-1=editor%3Dtinymce%26posts_list_mode%3Dlist; wp-settings-time-1=1424359234
Host:54.xxx.xx.xx
Origin:http://54.1xx.xx.xx
Referer:http://ift.tt/1Dufr6z
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
action:submit_contact_form
fullname:lalala
email:this@gmail.com
text:tetete
Response Headersview source
Connection:Keep-Alive
Content-Length:298
Content-Type:text/html; charset=iso-8859-1
Date:Thu, 26 Feb 2015 15:36:37 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.7 (Ubuntu)


This is my ajax part:



//send info to php
$.ajax({
beforeSend: function() {
if ( IsEmail(email) == false) {
$('#aboutUnsuccess').show("slow");
$('.form_content').hide("slow");
}
},
url: document.location.protocol+'//'+document.location.host+'/wp_admin/admin_ajax.php',
type: "POST",
/*action: 'submit_contact_form',*/
data: ({ "action": "submit_contact_form", "fullname": fullname, "email": email, "text": text }),
success: function (results){
if ( IsEmail(email) == true) {
//hide table
$('.form_content').hide('slow', function() {
$('.form_content').hide( "slow" );
});
//show textboxes
$('#aboutSuccess').show("slow");
$( "#aboutSuccess" ).append( "<iframe id=\"pixel-thing\" src=\"http://ift.tt/1Bh4iH8\" width=\"1\" height=\"1\" border=\"0\"></iframe>" );

}
}
});


});


And this is my php fucntion:



// Contact form Ajax

add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form');

function submit_contact_form(){

if(isset($_POST['email'])) {

$email = $_POST['email'];
$email_to = "mail@main.com";

$host = "ssl://smtp.gmail.com:465";
$username = 'mainmain@mail.com';
$password = 'pass';

$email_subject = "You have a new email from $email via yellowHEADInc.com website";
$message = $_POST['text'];

$headers = array ('From' => $email, 'To' => $email_to,'Subject' => $email_subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($email_to, $headers, $message);

if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo("Message successfully sent!\n");
}
}


}


Whay might be the cause of the error?



asked 2 mins ago

Hatul

642






Why do I get "POST http://ift.tt/1Bh4iH6 404 (Not Found)" when using Wordpress+Ajax?

Aucun commentaire:

Enregistrer un commentaire