ajax没有接收到GET术语


The GET term dose not get received by ajax

这是我的jquery:

$("#sq").autocomplete({
 source: function( request, response ) {
    $.ajax({
        url: "ajaxautocomplete.php",
        dataType: "json",
        data: {
        featureClass: "P",
        style: "full",
        maxRows: 6,
        name_startsWith: request.term
        },
            success: function( data ) {
            response( $.map( data, function( item ) {
                return {
                label: item ,
                value: item
                }
            }));
            }
    });
    },
    minLength: 1,
});

和我的php:

echo json_encode(array($_GET['term']));

问题是php没有收到这个术语。为什么?

您没有任何参数term。您正在传递以下数据:

   data: {
    featureClass: "P",
    style: "full",
    maxRows: 6,
    name_startsWith: request.term
   },

所以你可以通过以下方式获得:

echo $_REQUEST['featureClass'];
echo $_REQUEST['style'];
echo $_REQUEST['maxRows'];
echo $_REQUEST['name_startsWith'];

你没有任何term参数,我想你说的是name_startsWith

对于该用途:

echo json_encode($_REQUEST['name_startsWith']);

它应该是

     echo json_encode(array($_GET['name_startsWith']));

如果您想访问类似$_GET['term']的内容,那么AJAX请求中应该有类似term=somethingname-value-pair。它不在那里。

通过添加类型来尝试类似的操作:GET

$.ajax({
        url: "ajaxautocomplete.php",
        type:GET,
        dataType: "json",
        data: {
        featureClass: "P",
        style: "full",
        maxRows: 6,
        name_startsWith: request.term