Sending Html table data by ajax to php page - javascript

I am using laravel framework, I have one index page in that I am retrieving dynamic table from another page by ajax(using div). Then now I am allowing user to edit table values so now I want to send modified table data to next php to process some actions on those values. So how can take those modified table values and how to send it to next php page by ajax or php script. And how can I assign those ajax values to php varriables.Here is the snapshot of table

There are 2 jQuery datatables packages for Laravel (that i know of) which handle this kind of thing for you. No need for HTML in AJAX responses. Im using the one by Chumper and it makes things a lot easier. You just need to provide the data in your controller or route, and add the helper to your view.
https://github.com/Chumper/Datatable
https://github.com/bllim/laravel4-datatables-package << (haven't worked with this one)

Related

Getting the added gridview table data on the code behind

I have a gridview on my aspx (designer) file. I have added the rows through the generated gridview table through javascript to make the web more performance friendly, and I update the whole table using a save button. But I am not able to get the added rows on my code behind. Is there anyway for the browser to communicate that(new rows) to the code behind?
not an easy way - the server (code behind) doesn't know about any rows inserted by your javascript - so when you post back to the server, the rows are gone.
one solution would be:
Put your data in a server-known input-control, like a HiddenField in a serialized form.
Post back to your server and deserialize the data
Add the desirialized data to your gridview on the server

How to get data from form using JS, when the form has been returned from AJAX itself?

Here we have a <div id="content"> and inside it AJAX loads data from the server. We have preloaded JS scripts in the whole file.
Some of the server's AJAX answers are whole forms. That forms have the same ids, but different structures. What is needed is to pick the data from freshly baked forms came from the server via AJAX, using JavaScript and create a kinda queryString to send its data again to the server via AJAX itself.
What has been tried:
I put a code which is getting data from the form on the page using JS. It works great when the form is a static part of the page and i loaded within the initial DOM loading, but, after AJAX re-loading the real DOM is differ than that in the cache, which has been initially loaded with the page.
I tried to put JS code into the answer from the server with the form. But, it does not work as well. Even simple alert('Hello!') does not work.
I am new in AJAX so, please, do not judge me with all the severity.
Thanks!
If your issue is picking up only the latest baked forms, you can try the following approach:-
In each ajax call of the page, before setting the response content to the desired div, find all objects having class name called 'lastUpdated' (or any other unique class name that you can come up with) and remove all the lastUpdated class associations using the jQuery code
$('.lastUpdated').removeClass("lastUpdated");
Now set the response to the desired div and add the class 'lastUpdated' to this div alone.
Thus at any point of time,
$('.lastUpdated')
will help you pick the data from freshly baked forms came from the server

accessing client side jquery variable in server side groovy page

I have a variable in my JavaScript which contains the id of the clicked row in the master grid. I want to pass it to the groovy service page that handles my child grid so that it can filter the rows based on that id. How do I do that?
The problem is that your javascript-based grid runs on the client, while the page is rendered server-side. Therefore, some communication must take place in order to instruct your application to filter rows based on what the user selects.
Grails uses the MVC architecture, this means that there is a controller that takes care of answering the requests generated from the client. To answer these requests, the Controller can make use of the Views (.gsp files). So when you call to the URL controller/index you may make use of an index.gsp view to render your page.
What you need to do is to make an ajax call to a controller method (e.g. controller/getFilteredRows) that gets as input the selected row (could be its id) and based on some logic fetches all the required information and sends them back to the client encoded for example using JSON.
Now the client knows the rows it has to display, hence you can update your grid.

jQuery Select2 with spring and hibernate

I am using Tag functionality of select 2 in my spring application and hibernate to save it. I am using the AJAX call to save this form.
Till here it is working fine.
My problem is:
How can I populate the data from DB and display it in screen as tag so that user can update it. (this data has id and text)?
How can I save this data in DB using AJAX call. Basic form is saving but for this select2 data I am able to get only keys. I need proper Entity so that I can save/update it directly in DB?
an example will be very much appreciated. right now, I am not putting my code there. Please comment n this post if you want me to post any code.
FYI: I am new in spring and hibernate.

Ajax, Javascript, or Database for post/get results

I have a question about what backend to use. I have a html page that has various dropdown lists. On Submit I want to sent the results of that page to another page to compile the (average) results. Is there a way to do this without setting up a database? I was thinking of sending the data with Ajax and then compiling the data with Javascript on the receiving page.
I've done something like this before so any suggestions would be appreciated.
You can use jquery to check the changes in the dropdown list. Send the results to a jquery ajax page and get the return value as json. The result json can be shown on the same page with jquery.
I assume the page you are talking about is an html or jsp page. Yes you can use javascript ot process the data and then send it to a servlet and get it back to another jsp.

Categories