Last active
February 23, 2016 17:07
-
-
Save Moccine/aafa3a9dc4c5e4477662 to your computer and use it in GitHub Desktop.
Ajax Response Json LARAVEL5.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var $a = jQuery.noConflict(); | |
| $a(document).ready(function () { | |
| $a(".thumbnail.user").click(function () { | |
| $a.mydata = $a(this).myAjaxInit(); | |
| var type = $a.mydata.type; | |
| $a.getJSON($a.mydata.urlJson, function (data) { | |
| $a.pagination = $a(data) | |
| $a.pagination = $a($a.pagination[0]) | |
| $a.data = $a($a.pagination[0].data); | |
| var contentPage = $a(".bs-allbookmark"); | |
| contentPage.empty('slow'); | |
| var items = []; | |
| items.push(String("<thead>" + "<tr ><th colspan=\'3\'><h1 class=\' timeline-stacktrace-title\'>" + $a.mydata.title + "</h1></th>" + "</thead>")); | |
| $a.each($a.data, function (key, val) { | |
| items.push("<tr>" + "<td>" + key + "</td>" + "<td>" + key + "</td>" + "<td>" + $a.data.get(key)[type] + "</td>" + "</tr>"); | |
| }); | |
| var N, P; | |
| P = (($a.pagination.get(0).current_page) <= 0) ? ($a.pagination.get(0).current_page) - 1 : 5; | |
| N = (($a.pagination.get(0).current_page) < 5) ? ($a.pagination.get(0).current_page) - 1 : 0; | |
| items.push(String("<tfoot><tr><td colspan=\'3\'>" + "<ul class='pager'>" + "<li class='thumbnail user' id='" + P + "'>" + "<a href='#'>Previous</a></li>" + "<li class='thumbnail user' id='" + N + "'>" + "<a href='#'>Next</a></li>" + "</ul>" + "</tfoot></tfoot>")); | |
| $a("<table/>", {"class": "table table-hover table-bordered", html: items.join("")}).appendTo(contentPage); | |
| /*console.log($a.pagination.get(0))*/ | |
| }); | |
| return false; | |
| }); | |
| }); | |
| $a.fn.myAjaxInit = function () { | |
| var iduser, item, urlJson, title; | |
| item = $a(this).attr('name'); | |
| iduser = $a(this).attr('id'); | |
| urlJson = String("http://localhost/AUTHENTIFICATION/" + item + "/" + iduser); | |
| switch (item) { | |
| case 'vue': | |
| title = 'Les plus vue'; | |
| break; | |
| case 'url_bm': | |
| title = 'Bookmark'; | |
| break; | |
| default : | |
| title = item; | |
| } | |
| return {"id": iduser, "type": item, "urlJson": urlJson, "title": title}; | |
| } | |
| function progressAjax() { | |
| $a('#content_progress').ajaxStart(function () { | |
| $a(this).html("<img src='resources/assets/images/loader.gif ' alt='loader'>"); | |
| $a(this).fadeIn(); | |
| }); | |
| $a('#content_progress').ajaxComplete(function () { | |
| $a(this).fadeOut('slow'); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserController extends Controller | |
| { | |
| use ResetsPasswords; | |
| public function __construct(Request $request) | |
| { | |
| $this->middleware('auth'); | |
| } | |
| public function index() | |
| { | |
| return view('user.index'); | |
| } | |
| public function UserpageElements(Request $request, $column, $id) | |
| { | |
| if ($column == "vue") { | |
| $bestVue = DB::table('bookmarks')->where('user_id', $id)->simplePaginate(20, [$column, 'url_bm']); | |
| } else { | |
| $bestVue = DB::table('bookmarks')->where('user_id', $id)->simplePaginate(20, ['id', $column]); | |
| } | |
| return response()->json($bestVue); //->setCallback($request->input('callback')) ; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| Route::group(['middleware' => 'web'], function () { | |
| Route::auth(); | |
| Route::resource('user', 'UserController'); | |
| Route::get('/user', 'UserController@index'); | |
| Route::get('/user/{id}', 'UserController@show'); | |
| Route::post('/user/{id}', 'UserController@savePassword'); | |
| Route::get('/{category}/{id}', 'UserController@UserpageElements'); | |
| Route::get('/allUsers', 'UserController@allUsers'); | |
| Route::get('/addform', 'UserController@create'); | |
| Route::post('/addbm', 'UserController@store'); | |
| Route::get('/profilUser', 'UserController@profilUser'); | |
| Route::get('/oldPassword', 'UserController@oldPassword'); | |
| Route::post('/newPassword', 'UserController@newPassword'); | |
| Route::post('/savePassword', 'UserController@savePassword'); | |
| /*-------------------------------------------------------------------*/ | |
| Route::get('/','homeController@index'); | |
| Route::get('/index', 'HomeController@index'); | |
| Route::resource('Bookmark', 'BookmarkController'); | |
| Route::get('/Bookmark', 'BookmarkController@index'); | |
| Route::get('/allBookmark', 'BookmarkController@allBookmark'); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment