donglie7778 2014-12-03 13:17
浏览 39
已采纳

AJAX帖子在服务器端是空的(PHP)

I am making an AJAX request to a PHP controller, by using jQuery ajax, but when trying to get the posted data with PHP the $_POST is empty. Below is the actual function:

function GetSeriesForManufacturer(manuf) {
    selectedmanufacturer = manuf;
    //Make an AJax Call For Getting Series Of Manufacturer
    var series = null;
    $.ajax({
        type: "POST",
        url: url,
        data: "{manufacturer:'" + selectedmanufacturer + "'}",
        contentType: "application/json", //; charset=utf-8",
        dataType: "json",
        cache: false,
        async: false,
        success: function (response) {
            //remove loading gif
            $(".loading").hide();
            //Append Data
            AppendSeries($.parseJSON(response.text), selectedmanufacturer);
            //Custom Scrollbar Call
            $('.MatchingSeries ul').mCustomScrollbar();                        
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {  }
    });                         
}

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • douzuita7325 2014-12-03 13:46
    关注

    First, you don't need to stringify data. Just send object literal is ok.

    data: {manufacturer: selectedmanufacturer},
    

    Second, you don't need this line:

    contentType: "application/json",
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog