jeudi 7 novembre 2019

Laravel - Java script - Unable to load a page from web route url in ajax call

I'm passing a parameter in side the $ajax call to link with controller function.

abc.blade.php

inside onClick listener---

$.ajax({
    url: "",
    type: "GET",
    dataType:"json",
    data: {repc:repCode.trim()}, 
    success: function (data) 
    {
      alert("OK");
    }
});

web.php

Route::get('getFordHedGpsLocationForSelectedRep', 'MapController@getFordHedGpsLocationForSelectedRep')->name('getFordHedGpsLocationForSelectedRep');

MapController.php

public function getFordHedGpsLocationForSelectedRep(Request $request) 
    {
        $repCode  = $request->get("repc");

        $result = DB::select('select query to get data');

        $temp = array();
        $output = array();
        $output1 = array();

        foreach ($result as $key => $value) 
        {
            if (trim($value->RepCode) == $repCode) 
            {
                $temp['lat'] = $value->Latitude;
                $temp['lng'] = $value->Longitude;
                $temp['ref'] = $value->RefNo;
                $temp['sTime'] = $value->startTimeSO;
                $temp['eTime'] = $value->endTimeSO;
                $temp['repCode'] = $value->RepCode;
                $temp['debCode'] = $value->DebCode;
                $temp['tAmt'] = $value->TotalAmt;
                $temp['outDis'] = $value->OutDisVal;
                $temp['debName'] = $value->DebName;
                $temp['repName'] = $value->RepName;
                $temp['qty'] = $value->Qty;
                $temp['tDate'] = $value->TxnDate; 
            }                                     

            $output = isset($temp)?$temp:'';
        }

        $output1 = isset($output)?$output:'';       

        return view('selectedRepMap')->with(['repOrders'=> $output1]);

    }

That controller function returns a view (selectedRepMap.balde.php) with view loading data. Unfortunately page not loading automatically after the click event on abc.blade, but inspect network status got '200' for 'getFordHedGpsLocationForSelectedRep' function ($ajax call url) and double click on that function in inspect network area page loading successfully.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire