donglijuan8227 2017-02-13 13:36
浏览 228
已采纳

Ajax中的POST请求错误。 错误后的空白页面

When I press a button with some functionalities(in php code) I don't understand why I receive sometimes error, sometimes succes from ajax. I have one more button which have almost same structure of code to the bottom. So, I have 2 ajax codes with same structure(but different names of variables or files). Is this important ?

Ajax:

function plan_tarifar_submit_anulare() {
    var id = get_user_id_anulare();
    var myURL = "./UpdateAnularePlanTarifar.php";
    $.ajax({
        timeout: 5000,
        type: "POST",
        url: myURL,
        data: {id:id},
        error: function(xhr) {
            alert('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' -> ' + xhr.responseText);
            parent.location.reload();

        },            
        success: function (xhr) {
            alert('IT WORKS !!' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
            parent.location.reload();
        }
    });
    return false;
}

php:

     <?php
    /**
     * Description of updateAnularePlanTarifar (...)
     */
    require_once("../includes.inc.php");
    $cookie_value = assure_login_check();

    if (!isset($_POST['id'])) {
        return;
    }
    $user_id = htmlspecialchars($_POST['id']);
function getOldIstoric($id){
   (.....)   
    return $istoric;
}
function anularePlanTarifar($id) {
   (.....) 
}
anularePlanTarifar($user_id);
?>

Also, after error the page can't reload: unloaded page

I think that the id is missing at the end of url.

  • 写回答

1条回答 默认 最新

  • dtukyb8095 2017-02-14 12:45
    关注

    Depends on how your html code looks like. But I imagine there is something in a form tag.

    Check if you have those attributes for the form tag:

    <form action="#" method="post" onclick='plan_tarifar_submit_anulare();' id='yourID'> <!--something--> </form>

    It should look like this, or similar.

    Let me know if it works. If you still have problems, please show your html code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fastreport怎么判断当前页数
  • ¥15 Kylin-Desktop-V10-GFB-Release-JICAI_02- 2207-Build14-ARM64.iso有没有这个版本的系统啊
  • ¥15 能不能通过蓝牙将传感器数据传送到手机上
  • ¥20 100元python和数据科学实验项目
  • ¥15 根据时间在调用出列表
  • ¥15 R 包chipseeker 安装失败
  • ¥15 Veeam Backup & Replication 9.5 还原问题
  • ¥15 vue-print-nb
  • ¥15 winfrom的datagridview下拉框变成了黑色,渲染不成功
  • ¥20 利用ntfy实现短信推送