Ajax / jQuery请求后端的数据格式

时间:2013-10-24 16:30:06

标签: jquery ajax jquery-mobile

有人可以告知以下Ajax / jQuery请求发送到后端的数据格式。

这是我的Ajax / jQuery代码:

$( document ).on( "pageinit", "#myPage", function() {
    $( "#autocomplete" ).on( "listviewbeforefilter", function ( e, data ) {
        var $ul = $( this ),
            $input = $( data.input ),
            value = $input.val(),
            html = "";
        $ul.html( "" );
        if ( value && value.length > 2 ) {
            $ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
            $ul.listview( "refresh" );
            $.ajax({
                url: "/get_names/",
                dataType: "json",
                crossDomain: true,
                data: {
                    q: $input.val()
                }
            })
            .then( function ( response ) {
                $.each( response, function ( i, val ) {
                    html += "<li>" + val + "</li>";
                });
                $ul.html( html );
                $ul.listview( "refresh" );
                $ul.trigger( "updatelayout");
            });
        }
    });
});

1 个答案:

答案 0 :(得分:0)

这是JSON格式:

{name1 : value1, name2 : value2}

在后端你应该能够像这样简单地得到这个值:

$_GET['value1']
相关问题