php - Drupal 7 ajax not working properly (success function called but the drupal page is being printed instead of the page callbacks results) -


hello using ajax in drupal 7 data bounds of map serialize string , submit post server added filter view make display respond changes in zoom , array bounds.

the success callback called data returned not result of page callback function , xhtml response in firebug entire web page. appreciate knowing preventing page callback function value being returned.

below javascript code:

    (function ($) {     drupal.behaviors.mapresults = {     attach: function() {   // dynamically show  marker nodes      // first find right map     $.each(drupal.settings.getlocations, function (key, settings) {     // 1 want     alert("0");     if (1 == 1) {       // event handler on map zoom check if view results needs updated            on zoom        // hooking event , 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){              // bounds              marker_bounds = getlocations_map[key].getbounds();             // calculate horizontal distance bounds max  , min latitude ,          longitude for box         // submit data jquery bounds etc.         var marker_bounds_string = json.stringify(marker_bounds);          // ajax link submit data 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)); 

here drupal module code:

    <?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 display map options drupal_exit(); $view = views_get_view('search');  // set display $display_id = 'default';  // add filters ajax // float $bounds_array = json_decode($_post['marker_bounds'])  //get cordinates 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 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();     } } ?> 

mapresults_ajax not returning anything. in case, use print instead of return send results javascript without returning whole html page.

change drupal_json_output print drupal_json_output


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -