简体   繁体   English

$ .post和AJAX不能在服务器上运行,但在localhost中工作正常

[英]$.post & AJAX is not working on server, but working fine in localhost

I just moved my website on server and got socked by the result, $.post() and AJAX is not working on server. 我刚刚在服务器上移动了我的网站并被结果所取代, $.post()和AJAX无法在服务器上运行。

$.post() is always returning blank data. $.post()始终返回空白数据。 You can check in below one sample of $.post() in this case, when im alert(info) it shows Array() : 在这种情况下,你可以在$.post()一个样本下面检查,当im alert(info)它显示Array()

$(document).ready(function () {
    $("#faq").submit(function () {
        var data = $(this).serializeArray();
        $.post("worker.php", data, function (info) {
            $(".faq_status").fadeOut();
            $(".faq_body").prepend(info);
        });
        return false;
    });
});

The same thing is happening with all the $.post() & AJAX code. 所有$.post()AJAX代码都在发生同样的事情。 I don't know what to do. 我不知道该怎么办。

Here is my worker.php progress: 这是我的worker.php进度:

$question = addslashes(htmlentities($_POST['user_question']));
$uip = $_SERVER['REMOTE_ADDR'];

if ($question == "") {
    echo "<p class='alert alert-danger faq_status'>Problem in posting your query. Please resubmit it.</p>";
    exit;
}

$day = date('d');
$month = date('m');
$year = date('Y');

$sql = "SELECT no FROM user_faq WHERE user_ip = '$uip' AND EXTRACT(MONTH FROM asked_time) = $month AND EXTRACT(DAY FROM asked_time) = $day AND EXTRACT(YEAR FROM asked_time) = $year";

$record = $conn->query($sql);

if ($record->rowCount() >= 2) {
    echo "<p class='alert alert-danger faq_status'>Problem in posting your query. please resubmit it.</p>";
} else {
    $sql = "INSERT INTO `user_faq`(`no`, `question`, `user_ip`,`asked_date`) VALUES (NULL,:que,:ip,Now())";

    $query = $conn->prepare($sql);
    $query->bindValue(":que", $question, PDO::PARAM_STR);
    $query->bindValue(":ip", $uip, PDO::PARAM_STR);

    try {
        $query->execute();
        echo "<p class='alert alert-success faq_status'>We have receive your question, answer will be posted here soon!</p>";
    } catch (Exception $e) {
        echo "<p class='alert alert-danger faq_status'>Problem in posting your query. please resubmit it.</p>";
    }
}

Your post is working and returning this response on submit. 您的帖子正在运行,并在提交时返回此回复。

<p class='alert alert-danger faq_status'>Problem in posting your query. please resubmit it.</p>

Add Firebug extension to Firefox to easily debug your javascript. Firebug扩展添加到Firefox以轻松调试您的JavaScript。

It is possible that some configuration or error reporting on your localhost supresses or ignores warnings which doesn't on your server. 您的localhost上的某些配置或错误报告可能会抑制或忽略服务器上没有的警告。 The most effective way would be : 最有效的方法是:

1.Check for any javascript errors in your console related to your code. 1.检查控制台中与您的代码相关的任何javascript错误。

2.Echo something in your code at possible lines and debug to find where your script breaks. 2.在代码中以可能的行调用某些内容并进行调试以找到脚本中断的位置。

3.If you find the breakpoint, turn ON error reporting and check if there are any warnings/errors 3.如果找到断点,请打开错误报告并检查是否有任何警告/错误

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

相关问题 fullcalendar在localhost中工作正常,但在服务器中工作不正常 - fullcalendar is working fine in localhost but not in server javascript在localhost上工作正常,但在实时服务器上却不能 - javascript working fine in localhost but not on live server Fullpage js 在本地主机上工作正常但不在实时服务器中 - Fullpage js working fine localhost but not in live server AJAX发布请求无效,可以与邮递员发布请求一起正常工作 - AJAX post request not working, working fine with postman post request Ajax停止在Controller中处理$ POST,否则工作正常 - Ajax stops working on $POST in my Controller, else it's working fine 对服务器的AJAX POST请求不起作用 - AJAX POST request to server not working jQuery Ajax在本地主机上工作,但拒绝在服务器上工作 - Jquery Ajax working on localhost but refuses to work on server Ajax请求php在localhost上工作,但不在实时服务器上 - Ajax request to php working on localhost but not on live server Jquery-ui在Firefox中的localhost上可以正常工作,但在服务器上却不能? - Jquery-ui working fine on localhost in Firefox but not on server? 图像未显示在服务器上,但在节点 js 中的 localhost 上工作正常 - Images not showing up on server but working fine on localhost in node js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM