最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Redirect in Javascript with data (laravel 5.3) - Stack Overflow

programmeradmin2浏览0评论

I have to redirect on edit page with its data if user clicks on save button here is my button:

<button type="submit" name="edit" class="btn green" value="edit">Save</button>

When user click this button i get name of button here in update controller as

return $request->input('edit');

this return goes in to js file

success: function(result) {
    if (result == 'save_add') {
        window.location = "/student-management/list/create"
    } else if (result == 'edit') {
        window.location = "////////////////////////////"
    }else {
         window.location = "/student-management/list"
    }
}

route is

route('student.edit')

Here i am redirecting user to its actual path in case of edit on 2nd else if i want to redirect on edit page with its data i am working same here with other page in controller but i want to do this in js

if(Input::get('save_add')) {
    return redirect()->route('student.create');
} elseif(Input::get('edit')) {
    return redirect()->route('student.edit', ['id' => $id ]);
} else {
    return redirect()->route('student.index');
}

I want to send same as above id with that redirect for edit

I have to redirect on edit page with its data if user clicks on save button here is my button:

<button type="submit" name="edit" class="btn green" value="edit">Save</button>

When user click this button i get name of button here in update controller as

return $request->input('edit');

this return goes in to js file

success: function(result) {
    if (result == 'save_add') {
        window.location = "/student-management/list/create"
    } else if (result == 'edit') {
        window.location = "////////////////////////////"
    }else {
         window.location = "/student-management/list"
    }
}

route is

route('student.edit')

Here i am redirecting user to its actual path in case of edit on 2nd else if i want to redirect on edit page with its data i am working same here with other page in controller but i want to do this in js

if(Input::get('save_add')) {
    return redirect()->route('student.create');
} elseif(Input::get('edit')) {
    return redirect()->route('student.edit', ['id' => $id ]);
} else {
    return redirect()->route('student.index');
}

I want to send same as above id with that redirect for edit

Share Improve this question edited Nov 19, 2016 at 18:37 spender 121k35 gold badges244 silver badges367 bronze badges asked Nov 17, 2016 at 8:54 Ramzan MahmoodRamzan Mahmood 1,9012 gold badges24 silver badges51 bronze badges 9
  • It's not clear what your asking for help with. – Joe Commented Nov 17, 2016 at 9:07
  • @Joe dear i am asking to redirect page with id from js file where i have /////////////////////////// in my question as i am `return redirect()->route('student.edit', ['id' => $id ]); here – Ramzan Mahmood Commented Nov 17, 2016 at 9:10
  • does javascript know the id? what does the edit url look like -- how is the id passed in the url? – Joe Commented Nov 17, 2016 at 9:11
  • i am getting id just tell me please how to pass edit route in windows.location – Ramzan Mahmood Commented Nov 17, 2016 at 9:16
  • I don't know what the edit url is, so not sure how to answer that fully correctly – Joe Commented Nov 17, 2016 at 9:20
 |  Show 4 more ments

2 Answers 2

Reset to default 3

Assuming your JavaScript already knows the user's id in a variable called id, and the edit url to send to takes the form of /student-management/student/{id}:

window.location = "/student-management/student/" + id

You can try this

In your controller

return return response()->json(['success'=>true,'result'=>$request->input('edit'),'url'=> route('student.edit', ['id' => $id ])]);

Your js

success:: function(data)
{
 if(data.success)
  {  
      window.location = data.url
  }
}

Hope this will help

发布评论

评论列表(0)

  1. 暂无评论