Php Drupal 7 ajax工作不正常(调用了success函数,但打印的是Drupal页面,而不是页面回调结果)

Php Drupal 7 ajax工作不正常(调用了success函数,但打印的是Drupal页面,而不是页面回调结果),php,jquery,ajax,json,drupal,Php,Jquery,Ajax,Json,Drupal,您好,我在drupal 7中使用ajax从地图边界获取数据,将其序列化为字符串,并作为post提交到服务器,作为视图的过滤器添加,以使显示响应缩放和数组边界的更改 调用成功回调,但返回的数据不是页面回调函数的结果,firebug中的xhtml响应是整个网页。我非常希望知道是什么阻止了页面回调函数值的返回 下面是javascript代码: (function ($) { Drupal.behaviors.mapresults = { attach: function() {

您好,我在drupal 7中使用ajax从地图边界获取数据,将其序列化为字符串,并作为post提交到服务器,作为视图的过滤器添加,以使显示响应缩放和数组边界的更改

调用成功回调,但返回的数据不是页面回调函数的结果,firebug中的xhtml响应是整个网页。我非常希望知道是什么阻止了页面回调函数值的返回

下面是javascript代码:

    (function ($) {
    Drupal.behaviors.mapresults = {
    attach: function() {
  // Dynamically show  the marker nodes
     // first find the right map
    $.each(Drupal.settings.getlocations, function (key, settings) {
    // this is the one we want
    alert("0");
    if (1 == 1) {
      // an event handler on map zoom to check if the view results needs to be updated     
      on zoom 
      // hooking another event and checking zoom may work better.
      google.maps.event.addListener(getlocations_map[key], 'bounds_changed', function()
      {

        // count number of markers <= 10'
        // global_settings.mgr
        //mgr = new MarkerManager(getlocations_map[key]);

         //zoomcount = mgr.getMarkerCount(getlocations_map[key].getZoom());
         zoomcount = 10;
         if(zoomcount < 100){
             // get bounds
             marker_bounds = getlocations_map[key].getBounds();



         // calculate horizontal distance from bounds to get max  and min latitude and
         longitude for the for box
        // submit data with jquery get bounds etc.
        var marker_bounds_string = JSON.stringify(marker_bounds);

        // ajax link to submit data by post
        $.ajax({
            type: 'POST',
            url: 'ajax/mapresults',
            dataType: "json",                   
            data : {marker_bounds : marker_bounds_string},             
            success: function (data)    
     {document.getElementById('map_results').innerHTML = "success";},
            error: function (xmlhttp)  
     {document.getElementById('map_results').innerHTML = xmlhttp.status;}
            });


        }
         else{

         }
      });
    }
  });
}
};
}(jQuery));
(函数($){
Drupal.behaviors.mapresults={
附件:函数(){
//动态显示标记节点
//首先找到正确的地图
$.each(Drupal.settings.getlocations,函数(键,设置){
//这就是我们想要的
警报(“0”);
如果(1==1){
//映射缩放上的事件处理程序,用于检查是否需要更新视图结果
变焦
//挂接另一个事件并检查缩放效果可能会更好。
google.maps.event.addListener(getlocations\u map[key],'bounds\u changed',function()
{

//计数标记数mapresults\u ajax没有返回任何内容。在这种情况下,我将使用print而不是return将结果发送回javascript,而不返回整个HTML页面


将drupal_json_输出更改为打印drupal_json_输出

检查ypur代码。PHP在
drupal_exit();
    <?php
function mapresults_menu() {
  $items['ajax/mapresults'] = array(
    'title' => t('mapresults AJAX'),
    'type' => MENU_CALLBACK,
    'page callback' => 'mapresults_ajax',
    'access arguments' => array('access content'),
  );
  return $items;
}
function mapresults_ajax() {
// call back for display map options
drupal_exit();
$view = views_get_view('search');

// set display
$display_id = 'default';

// add filters from ajax
// float
$bounds_array = json_decode($_POST['marker_bounds'])

//get cordinates from bounds_array
$lat_min = $bounds_array[0][0];
$lat_max = $bounds_array[1][0];
$lon_min  = $bounds_array[0][1];
$lon_max = $bounds_array[1][1];

// add filters to view
$view->exposed_input['ubicacion_latitiude'] = $lat_min;
$view->exposed_input['ubicacion_latitiude_1'] = $lat_max;
$view->exposed_input['ubicacion_longitude'] = $lon_min;
$view->exposed_input['ubicacion_longitude_1'] = $lon_max;

$view->pre_execute();
$view->execute();

// display ajax results in container
$data = $view->preview($display_id);
$results_count = count($view->result);

if($results_count <= 10){
    // Return json      
    drupal_json_output($data);//
drupal_exit();
}
else{
    drupal_json_output("ih");
drupal_exit();
    }
}
?>