简体   繁体   English

为什么在使用Wordpress + Ajax时会收到“ POST http://54.xx.xx.xx/wp-admin/admin-ajax.php 500(内部服务器错误)”的信息?

[英]Why do I get “POST http://54.xx.xx.xx/wp-admin/admin-ajax.php 500 (Internal Server Error)” when using Wordpress+Ajax?

It's the first time for me using ajax on WP. 这是我第一次在WP上使用ajax。 I am working on a simple contact form, and for some reason whenever I click submit I get an error: 我正在使用一个简单的联系表单,由于某种原因,每当我单击提交时,我都会收到错误消息:

on console: 在控制台上:

 POST http://54.xxx.xx.xx/wp-admin/admin-ajax.php 500 (Internal Server Error)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.xx.xx.xx:80
Request URL:http://54.xx.xx.xx/wp-admin/admin-ajax.php
Request Method:POST
Status Code:500 Internal Server Error
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:73
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.xx.xx.xx
Origin:http://54.xxx.xx.xx
Referer:http://54.xxx.xx.xx/?page_id=73
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:test
email:test@gmail.com
text:test
Response Headersview source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://54.xxx.xx.xx
Cache-Control:no-cache, must-revalidate, max-age=0
Connection:close
Content-Length:0
Content-Type:text/html; charset=UTF-8
Date:Thu, 26 Feb 2015 16:10:19 GMT
Expires:Wed, 11 Jan 1984 05:00:00 GMT
Pragma:no-cache
Server:Apache/2.4.7 (Ubuntu)
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Powered-By:PHP/5.5.9-1ubuntu4.5
X-Robots-Tag:noindex

This is my ajax part: 这是我的ajax部分:

//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://54.xxx.xx.xx/wp-content/themes/twentyfifteen-child/thePixel.html\" width=\"1\" height=\"1\"  border=\"0\"></iframe>" );

            }
        }
    }); 


});

And this is my php fucntion: 这是我的php功能:

// 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 asdasd.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? 是什么原因引起的错误?

I tried var_dump() the variables in the php functions.php file, They all display fine. 我试了var_dump()php functions.php文件中的变量,它们都显示正常。

when I add require_once "Mail.php"; 当我添加require_once "Mail.php"; on the top of my php file, pages just stop loading. 在我的php文件的顶部,页面刚刚停止加载。 I'm not sure this is the problem. 我不确定这是问题所在。 So I'm trying without it (?) 所以我正在尝试没有它(?)

The error 500 is throwing because your server is not responding to your call. 由于服务器没有响应您的呼叫而引发错误500。

Did you tried with at start of the php file. 您是否在php文件开始时尝试过。

error_reporting(E_ALL);
ini_set("display_errors", 1);

Use firebug so it will post you the call to server and response so you could see the error. 使用firebug,它将把您的呼叫发布到服务器并做出响应,这样您就可以看到错误。

If you are seeing a blank page,then you missed a syntax somewhere in your PHP file. 如果看到空白页,则您错过了PHP文件中某处的语法。 Have a look into your brackets, colons and semi-colons 看一下您的括号,冒号和分号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在使用Wordpress + Ajax时会收到“ POST http://54.xx.xx.xx/wp-admin/admin-ajax.php 500(内部服务器错误)”的信息? - Why do I get “POST http://54.xx.xx.xx/wp-admin/admin-ajax.php 500 (Internal Server Error)” when using Wordpress+Ajax? POST http://localhost/website/wp-admin/admin-ajax.php 400(错误请求) - POST http://localhost/website/wp-admin/admin-ajax.php 400 (Bad Request) AJAX 调用我收到“/wp-admin/admin-ajax.php 400(错误请求)”错误 - AJAX call I receive the “/wp-admin/admin-ajax.php 400 (Bad Request)” error 未能加载 wp-admin/admin-ajax.php:1 资源:服务器在 Wordpress Ajax 调用中响应状态为 400(错误请求) - Failed to load wp-admin/admin-ajax.php:1 resource: the server responded with a status of 400 (Bad Request) in Wordpress Ajax Call 对/wp-admin/admin-ajax.php的DDoS攻击 - DDoS attack on /wp-admin/admin-ajax.php POST /wp-admin/admin-ajax.php 400(错误请求) - POST /wp-admin/admin-ajax.php 400 (bad request) 对 wp-admin/admin-ajax.php 的请求返回 404 错误 - Requests to wp-admin/admin-ajax.php return 404 error admin-ajax.php - 服务器响应状态为 500(内部服务器错误) - admin-ajax.php - the server responded with a status of 500 (Internal Server Error) Wordpress wp-admin登录面临HTTP错误500(内部服务器错误)问题 - Wordpress wp-admin login facing with HTTP Error 500 (Internal Server Error) issue Windows上的admin-ajax.php错误500 - admin-ajax.php error 500 on windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM