在https(PHP)上发布ajax

时间:2017-06-30 18:23:38

标签: javascript php jquery ajax mysqli

是的,我知道已经存在这样的问题,但我仍然没有得到我做错的事情......

基本上我在jquery中用PHP页面做一个简单的Ajax帖子,但是xhr状态返回给我HTTP 500

这里是代码:

    function Register(mailval) {
    var dataString = 'email1=' + mailval;

AJAX

    // AJAX code to submit form.
    $.ajax({
    type: "POST",
    url: "register.php",
    data: dataString,
    cache: false,
    success: function(data) {
        alert(data);
        $(".modal-body").html('');
        $(".modal-body").html(data);
    },
      error: function (xhr, ajaxOptions, thrownError) {
        console.log(xhr.status);
        console.log(thrownError);
      }     
    });

}

PHP

<?php
$email2 = $_POST['email1'];
$connection = mysqli_connect("127.0.0.1", "user", "psw"); 
$db = mysql_select_db("wnarshix_contatti_form", $connection);
if (isset($_POST['email1'])) {
    $query = mysql_query("insert into user_registered(mail) values ('$email2')");
    echo "Grazie per esserti registrato";
}
mysqli_close($connection); 
?>

我没有正确使用mysqli?

0 个答案:

没有答案