Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
Modal de redirección de Javascript en Laravel

Cuando al usuario le gusta una historia en la tarjeta, los usuarios la guardan con el botón "guardar". Hago esto como un savePost en mi archivo .js. Pero si el usuario no está registrado, estoy redirigiendo como "ubicación.reemplazar (APP_URL + "/login")".

Quiero redirigir a un modal en la página de inicio en lugar de /login. ¿Es posible para mí hacer esto como una sesión o algo así?

 function savePost(t) { $.ajaxSetup({ headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content") } }); $(this); $.ajax({ url: APP_URL + "/save_favorite", type: "POST", dataType: "json", data: { item: t, _token: $('meta[name="csrf-token"]').attr("content") }, success: function(e) { 1 == e.bool ? $("#save-icon-" + t).removeClass("text-muted").addClass("icon-filled") : 0 == e.bool && $("#save-icon-" + t).removeClass("icon-filled").addClass("text-muted") }, error: function(e) { location.replace(APP_URL + "/login") } }) }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Su JS actual:

 function savePost(t) { $.ajaxSetup({ headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content") } }); $(this); $.ajax({ url: APP_URL + "/save_favorite", type: "POST", dataType: "json", data: { item: t, _token: $('meta[name="csrf-token"]').attr("content") }, success: function(e) { 1 == e.bool ? $("#save-icon-" + t).removeClass("text-muted").addClass("icon-filled") : 0 == e.bool && $("#save-icon-" + t).removeClass("icon-filled").addClass("text-muted") }, error: function(e) { location.replace(APP_URL + "/targetPage?showModal=1") } }) }

Al final de su página de destino agregue:

 @if(isset($_GET['showModal']) && $_GET['showModal'] == 1) <script type='text/javascript'> $(window).on('load', function() { $('#your modal id').modal('show'); }); </script> @endif

En tus rutas/web.php agrega esto:

 Route::get('/', function () { if(Auth::guest()){ return view('target.page'); } else { return redirect('/somewhere'); } });
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!