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.

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

报告相同问题?

悬赏问题

  • ¥50 STM32L431RCT6 定时器2中断发起ADC 采样问题
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker