2015-04-27 2 views
0

У меня есть ajax, который получает значение от back-end сервлета, теперь я хочу передать значение успеха в функцию скрипта Java. Как передать это?Передача значений значения ajax в функцию JS

Значение успех должен быть вставлен в этой линии населенные пункты: [result3],

Вот мой Java Script:

<script type="text/javascript"> 


    var result3; 
    function main() 
    { 
    $.ajax({ 
      url:'insertPos', 
     // data: {data : data}, 
      type:'get',    
      success:function(value)  
      { 
        result3= value; 
        callBackHnadler(result3) 

      } 

     }); 

    } 

    function callBackHnadler(response) { 



    MQA.EventUtil.observe(window, 'load', function() { 

    /*Create an object for options*/ 
    var options={ 
     elt:document.getElementById('map'),  /*ID of element on the page where you want the map added*/ 
     zoom:12,         /*initial zoom level of map*/ 
     latLng:{lat: 12.922050, lng: 77.559933}, /*center of map in latitude/longitude*/ 
     mtype:'osm'        /*map type (osm)*/ 
     }; 

    /*Construct an instance of MQA.TileMap with the options object*/ 
    window.map = new MQA.TileMap(options); 

    MQA.withModule('route','routeio','largezoom','mousewheel','viewoptions',function() { 



     /*Creates an MQA.RouteIO instance giving the endpoint of our new Directions Service as the 
     first parameter and true that we will not use a proxy as the second (enables JSONP support to 
     avoid server side proxies for route request and results communication).*/ 

     var io = new MQA.RouteIO(MQROUTEURL,true); 

     /*Creates an MQA.RouteDelegate for defining default route appearance and behavior.*/ 
     delegate = new MQA.Route.RouteDelegate(); 

     /*The delegate is also required to customize the pois, in this sample adds rollover content*/ 

     var strContent = new String(); 
     strContent += "<h1><i><p><a href='javascript:insert();'>insert</a></p></i></h1> <h1><i><p><a href='javascript:RePosition();'>re-position</a></p></i></h1> <h1><i><p><a href='javascript:remove();'>remove</a></p></i></h1> <h1><i><p><a href='javascript:convert();'>convert</a></p></i></h1> "; 
     delegate.customizePoi = function(thePoi) { 
     thePoi.setRolloverContent("Stop # : " + thePoi.stopNumber); 
     thePoi.setInfoContentHTML(strContent); 
     }; 

     /*Creates an MQA.RouteController for managing the route while it is on the map. A key function of the route 
     controller is to provide dragging capabilities to a route. The last parameter here is optional and is what is used 
     to determine if the route should be draggable (this will be true by default if not provided).*/ 
    routeController= map.createRoute(delegate,io,{routeOptions:{routeType:'fastest'},ribbonOptions:{draggable:true, draggablepoi:true,ribbonDisplay:{color:"#00FF40", colorAlpha:0.75}}}); 


     /*Executes the route request back to our Directions Service.*/ 
     io.route({ 

     /*First parameter to the MQA.RouteIO.route function defines the route request.*/ 
     locations: [response], 
     mapState: routeController.delegate.virtualMapState(map) 
     }, 

     /*The second parameter to the MQA.RouteIO.route function defines the IO settings.*/ 
     { timeout: 10000 }, 

     /*The final parameter to the MQA.RouteIO.route function is the callback function to execute 
     the IO request as completed.*/ 
     function(results) { 

     /*Takes the results of the route request and applies them to the map. The route ribbon will 
     be drawn on the map along with the placement of POI's at each point.*/ 
     routeController.setRouteData(results.route); 


     /*Change the map to display a best fit of the data.*/ 
     map.bestFit(); 


     });                                       
     map.addControl(
     new MQA.LargeZoom(), 
     new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT, new MQA.Size(1505,50))); 
     map.enableMouseWheelZoom(); 
     map.addControl(new MQA.ViewOptions()); 

    });  

    }); 

    } 
</script> 
+0

tl; dr: Вы не можете - вместо этого , вызовите 'MQA.EventUtil.observe' из функции' success'. – Amadan

+0

Я не пробовал это –

+0

Как это сделать; –

ответ

0

попробовать это,

function callBackHnadler(response) { 
 
    console.log(response); 
 

 
} 
 

 

 
var result3; 
 

 
function main() { 
 
    $.ajax({ 
 
    url: 'insertPos', 
 
    // data: {data : data}, 
 
    type: 'get', 
 
    success: function(value) { 
 
     result3 = value; 
 
     callBackHnadler(result3) 
 

 
    } 
 

 
    }); 
 

 
}

+0

Я пробовал этот, но не работал –

+0

Есть ли какие-либо ошибки на консоли ??? – syms

+0

Нет ошибки, но моя карта не загружается –

Смежные вопросы