nionta's avatar

Route is not loading in addressbar

this is my code:

 public function valuepass(Request $request)
{   
    $person_type = $_GET['person_type'];
    $company_id = $_GET['company_id'];

    dump($person_type);
    $allentryfields = DB::table('fields')
                    ->where([['fields.company_id',$company_id],['fields.person_type',         $person_type]])
                    ->join('field_types','fields.field_type_id','=','field_types.id')
                    ->select('fields.id as field_id','fields.field_name as field_name','field_types.type_name as type_name')
                    ->get();

 
    return view('admin.academicuser.createuser',compact('allentryfields'));

}

here the method 'valuepass' is getting two variable named person_type and company_id, along with this I want to change my view page, for this I have used "return view", there is no error and the button which onclick function return this valuepass method, also access on the view page, which I have checked in the web-network section. But problem is, the view page is not loading in the address-bar,

this is my route:

Route::get('acamedicpersonentry/{company_id}    /{person_type}','AcademicUserEntryController@valuepass'); 

how, can I solve this?

I have also tried this one:

 public function valuepass(Request $request)
{   
    $person_type = $_GET['person_type'];
    $company_id = $_GET['company_id'];

    dump($person_type);
    $allentryfields = DB::table('fields')
                    ->where([['fields.company_id',$company_id],['fields.person_type',  $person_type]])
                    ->join('field_types','fields.field_type_id','=','field_types.id')
                    ->select('fields.id as field_id','fields.field_name as field_name','field_types.type_name as type_name')
                    ->get();

   // return View('admin.academicuser.createuser', array('allentryfields' => $allentryfields));
    //return view('admin.academicuser.createuser',compact('allentryfields'));
   //return Redirect::route('academicuser/createuser')->with('allentryfields', $allentryfields);
   return redirect('academicuser/createuser')->with('allentryfields', $allentryfields);
   //                 return $allentryfields;

}


 public function index()
{
    $allentryfields = session()->get( 'allentryfields' );
    return view('admin.academicuser.createuser',compact('allentryfields'));

}

but, here is also the same problem, everything is okay but not loading in the address-bar, what could be the solution?

0 likes
10 replies
lostdreamer_nl's avatar

When you try and open that page, keep you network tab on the developer toolbar (F12) open.

Are you getting a 404, a 500, or a 200 response ?

note: You should not be using $_GET within laravel, use $request->person_type instead.

nionta's avatar

I am not facing any problem, the code working fine, and I have checked that the button getting the routes(checked in web-network), the problem is only that "url is not loading in the address-bar". the network tab response is 200

nionta's avatar

this is my javascript in view file:

 $('#academicuserbtn').click(function() {
               var company_id = $('#company option:selected').val();
               var person_type = $('#role option:selected').val();
             $.ajax({
             url: 'acamedicpersonentry/{company_id}/{person_type}',
             type: 'GET',
             data: { company_id:company_id,
             person_type:person_type
              },
             success: function(response)
             {
                 console.log('okay');
             }
            
             });
             console.log(company_id);
            console.log(person_type);
           });
nionta's avatar

@Smally , I think this is not the solution what I am finding. you have just give a solution for value passing, but I can passing my value to the controller file, there's no problem. thank you :)

lostdreamer_nl's avatar

The 'problem' is........

You are using ajax and are expecting the URL to change.

When you use ajax, the URL will not change, because you are not sending the user to another page, you are getting that page in the background.

The only thing you can do if you really want this (I wouldn't) is manually add that new URL to their browser's history object :

$.ajax({
    url: `acamedicpersonentry/${company_id}/${person_type}`,
    type: 'GET',
    success: function(response) {
        console.log('okay');
        window.history.pushState(response, "Title", "/new-url");
    }
});
1 like
nionta's avatar

@lostdreamiter_nl , thank's. it's loading on the address-bar now, but what I have to done is, I have to reload the browser, only then the next view page is showing; can you please tell me how to solve this problem?

lostdreamer_nl's avatar

@nionta What is it exactly what you are trying to do and why are you using AJAX for it ?

If you want the browser to show the new location, and show that page, why would you be using AJAX at all? simply send the user to the right address:

$('#academicuserbtn').click(function() {
    var company_id = $('#company option:selected').val();
    var person_type = $('#role option:selected').val();
    location.href = "/acamedicpersonentry/"+ company_id + "/" + person_type 
});

If you need to use ajax, you should know how to add content to the current page.

Something like :

$.ajax({
    url: `acamedicpersonentry/${company_id}/${person_type}`,
    type: 'GET',
    success: function(response) {
        $('#container').html(response);
    }
});
1 like
newbie360's avatar

anyways, don't know what you try to do, may be over coding / think too much ?

why don't just redirect with session to index, and in the index.blade.php check if has session

// index.blade.php
@if (session('allentryfields'))
    // do your actions
@endif

or you want pass variable to another method ?

return redirect()->action('TestController@index', ['allentryfields'] => $allentryfields);
1 like

Please or to participate in this conversation.