繁体   English   中英

无法发送数据ajax请求

[英]Failure to send data ajax request

这是我的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为空,请告诉我哪里错了?

请参阅http://api.jquery.com/jQuery.ajax/

数据选项可以包含格式为key1 = value1&key2 = value2的查询字符串,也可以包含格式为{key1:'value1',key2:'value2'}的对象。 如果使用后一种形式,则在发送数据之前,将使用jQuery.param()将数据转换为查询字符串。 可以通过将processData设置为false避免此处理。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM