PHP脚本的$ .ajax帖子间歇性地工作

时间:2016-11-11 18:07:45

标签: javascript php jquery ajax amazon-dynamodb

我正在尝试将变量发送到将发送电子邮件的php脚本。它的工作时间约占75%。我想我已经把它缩小到变量,有时候没有进入php页面,但我不知道为什么。以下是我的代码:

///////////////////////的Javascript /////////////////////// //

function postData(randomstring) {
var eml = $("#txtEmail").val();
$.ajax({
    type: "POST",
    url: "/api/v1/fp_eml/",
    dataType: "json",
    async: false,
    data: JSON.stringify({ email: eml, password: randomstring }),
    contentType: "application/json; charset=utf-8",
    complete: function () {
        alert("Password reset, email sent.");
        window.location.href = "/";
    },
    error: function (err) {
        console.log(err);
    }
});
}

/////////////////////// PHP /////////////////////// //

// process client request (Via URL)
header("Content-Type:application/json");

include("../../../api/aws/aws-functions.php");

// Get POST data
$request_body = file_get_contents("php://input");
$json = json_decode($request_body, true);
$data = array($json);

$email=$data[0]['email'];
$password=$data[0]['password'];

error_log($email);

$account=get_account($email);

if(empty($account))
    echo "Something went wrong";
else
    // send email to customer with password
    $to = $email;
    $subject = "Forgot Password";
    $txt = "Your password has been reset to: " . $password . "\n" . "Please log in immediately and reset your password." . "\n" . "If you did not request your password to be reset, please contact us immediately.";
    $headers = "From: test@email.com";

    $sent = mail($to,$subject,$txt,$headers);
错误记录////////////////////// ///

[11-Nov-2016 17:50:20 UTC] test@email.com
[11-Nov-2016 17:52:54 UTC] test@email.com
[11-Nov-2016 17:53:20 UTC]
[11-Nov-2016 17:53:20 UTC] PHP Fatal error:  Uncaught exception
Aws\DynamoDb\Exception\DynamoDbException' with message 'Error executing
"Query" on "https://dynamodb.us-west-2.amazonaws.com"; AWS HTTP error: 
Client error: `POST https://dynamodb.us-west-2.amazonaws.com` resulted in a 
`400 Bad Request` response
{"__type":"com.amazon.coral.service#SerializationException","Message":"Start 
of list found where not expected"} SerializationException (client): Start of 
list found where not expected - 
{"__type":"com.amazon.coral.service#SerializationException","Message":"Start 
of list found where not expected"}'
exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: 
`POST https://dynamodb.us-west-2.amazonaws.com` resulted in a `400 Bad 
Request` response:
{"__type":"com.amazon.coral.service#SerializationException","Message":"Start of list found where not expected"}
' in  home/mjohn1404/public_html/api/aws/GuzzleHttp/Exception/RequestException.php:107 Stack trace:#0 home/mjohn1404/public_html/api/aws/GuzzleHttp/Middleware.php(65): GuzzleH in home/mjohn1404/public_html/api/aws/Aws/WrappedHttpHandler.php on line 159

正如你所看到的那样,17:50和17:52的测试工作正常,但17:53的测试失败了。无法识别电子邮件地址,因此数据库查询失败。任何正确方向的援助将不胜感激。谢谢大家的时间。

0 个答案:

没有答案