当 ajax url 是 '/' 时,会执行什么

What is exectuted when ajax url is '/'?

本文关键字:执行 什么 url ajax      更新时间:2023-09-26

我觉得问这个问题很傻,但我被难住了。

我做程序员已经很多年了,但我对jQuery和ajax相当陌生。

我必须更新一个现有的WordPress网站,其中数据位于名为site_map_equipment的MySQL数据库中。 该表有 5 列:eid、mapkey、name、描述和协议。

显示信息的 ajax 调用是:

function getMapEquipmentData(mapkey) {
  $.ajax({
    url: '/',
    data: "map_equipment=" + mapkey,
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    beforeSend: function() {
      $('.mapkey-content').html('<p><img src="' + imgurl + '/loading.gif" width="16" height="16" alt="Loading..." /></p>');
    },
    success: function(request) {
      $('.mapkey-content').html('<img src="' + imgurl + '/map-key-icon-' + mapkey + '.png" width="27" height="24" alt="" /><h5>' + request.name + '</h5><p>' + request.description + '</p>');
    },
    error: function(request, err) {
      $('.mapkey-content').html('<p>A problem occured while accessing the data.</p>');
    }
  });
}

另一个 ajax 调用指定了一个 url '/wrhsac/',我认为这将是一个子目录,但不存在这样的子目录。

我一直将ajax调用定向到PHP文件,但是当url为"/"或"/wrhsac/"时,执行请求的是什么?

感谢您的提示!

根据我得到的提示,它让我在几个我没有想到的地方看。

低,看看WordPress函数.php文件:

parse_str($_SERVER['QUERY_STRING']);
if( $map_equipment != null ) {
    $result = $wpdb->get_row('SELECT * FROM `site_map_equipment` WHERE `mapkey`=' . $map_equipment, ARRAY_A);
    print json_encode($result);
    exit();
}