无法发送数据ajax请求

时间:2017-08-17 21:29:16

标签: javascript php jquery ajax

这是我的jQuery代码:

$("li").on('click', function (event) {
    event.preventDefault();

    $.ajax({
        url: "/ads/updateads", // Url to which the request is send
        type: "POST",             // Type of request to be send, called as method
        data: {name: 'mhf'}, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
        contentType: false,       // The content type used when sending data to the server.
        cache: false,             // To unable request pages to be cached
        processData: false,        // To send DOMDocument or non processed data file it is set to false
        success: function (data)   // A function to be called if request succeeds
        {
            console.log(data);
        },
        error: function () {
            $('body').append('Errrrrrror');
        }
    });
});

我的php代码在这里:

 <?php
    echo '<pre>';
    print_r($_POST);
?>

和html代码:

<ul id="myselect">
    <li>Item 1</li>
    <li>Item 2</li>
</ul>

但是$ _POST是空的,请告诉我哪里出错了?

1 个答案:

答案 0 :(得分:0)

参考http://api.jquery.com/jQuery.ajax/

  

data选项可以包含表单的查询字符串   key1 = value1&amp; key2 = value2,或{key1:&#39; value1&#39;形式的对象,   key2:&#39; value2&#39;}。如果使用后一种形式,则转换数据   在发送之前使用jQuery.param()将查询字符串转换为查询字符串。这个   通过将processData设置为false ,可以规避处理。