Ajax call doesn't work when data is large - javascript

Hi, I am doing Dynamic web project in Eclipse.
I am using jsp 2.0 and servlet 3.0
In some cases I need to transfer data to server and work on it and come back to same page, so at that time I am in jsp page So I transfer data using ajax and so it will send data without referencing page.
I make the ajax call into loop. It works successfully
$.ajaxSetup({async:false});
$.get('SaveMappingToXML',{objText:selectedTargetObjectsText[li],objVal:selectedTargetObjectsValue[li],rowSrc:mappingSourceFieldValue,rowDesti:mappingTargetFieldValue,rowSrcName:mappingSourceFieldName,rowDestiName:mappingTargetFieldName,sizeOfMapping:rows,objSize:sizeOfSelectedObj,boolVal:li,extID:externalID,refString:mappingReferences},function(res){
//alert("ajax call successfully.... :)");
});
In above example all element are passed into ajax without index are array of javaScript
so while i am pass 400 element into mappingReferences parameter ajax can't call and my web project display me error...
Above ajax call is written into jsp page so I can't debug this page...
So there is any limitation to pass number of arguments into ajax.
I am trying to print that array into <textarea> it will display whole array means java Script support 400 element in array so there are any limitation of ajax to pass multiples of elements in to one array...

If data length is a prob then you should use $.post here. Please go through to the link difference of $.post and $.get
or visit this link
Hope this will help you.

Related

Using Select 2 drop down for large data more than 10000 Search

Hello every one i want to use select 2 drop down which can easily filter
more than 10000 record butt in the given link
http://jsfiddle.net/a8La61rL/10/
using script a large function that is not good to use in every page
is there is any to use this script in a separate file and send list of array
objects to this method for populating and searching
This is possible with the following steps.
1- Make an ASPX webservice or Web page function which will fetch a list of these records from a file using C#/Vb file handling and return in JSON array.
2- Use jQuery $.ajax method to fetch this json array from ASPX function or Webservice.
3- Bind the select2 in jQuery success event.
This will become a call, and on every page you can include this script and bind data. For better performance, you can also fetch first time from file and save in session or cookie and whenever any other page will call, it will fetch from session or cookie. I can explain further if required.

How to pass a value to MySQL from an infinitely looping Javascript function?

I'm trying to write a simple web app that will read from a 1D barcode and insert the value to a MySQL database.
Ideally this website will access to a camera and just scan the barcodes, that are shown to it. There will be no further user interaction.
I have achieved scanning the barcodes and extracting the information in Javascript using ZXing. Now my research has shown me that you can't just insert a php inside javascript. So I must stop the infinite loop of the function and pass data to php, where it can be inserted to MySQL. However after I return from the function and update the database, I need to refresh the webpage to scan a new barcode.
The problem is here I don't want to refresh the webpage because the browser, that runs the webpage won't have any mouse/keyboard(user interaction). How can I call a javascript function infinite times without refreshing my browser?
After scaning, send data to php by ajax (try some javascript framework like jQuery or others...)
By javascript, you can refresh page in oncomplete state of ajax request without any keybord or mouse action.
I think your best chance is to take a look to javascript Ajax calls.
In client side
- The infinite loop call to a function that handles de ajax call. That ajax call should sent a GET o POST to a php page.
- You don't need to refresh the page. If you need to return some data, do it in the ajax response function.
In the server side
The .php handle the insertion of data to MySQL.
Recomendation:
Use jQuery, a javascript library: https://jquery.com/
Take a look:
Using Jquery Ajax to retrieve data from Mysql

Execute jquery ajax function after PHP POST

I am creating a mobile app, using jQuery Mobile and Ajax calls to PHP.
I have several mobile pages defined in the same php-file that lets the user filter down on location, type of item etc using listviews.
On some of my PHP pages I am using forms in panels to add new records.
Everything works fine except I can't figure out how to get back to the same page with the same selections, after I have added a record with a form POST?
In the normal selection workflow I use a Ajax call to populate the page in question with the correctly filtered data, based on the previous page, but to do that I would have to execute the jQuery Ajax function in my page when the page is created with PHP.
To do that the only way I have come up with is to use the PHP header function and submit the search parameters in the URL and then catch these when the web page is created and dynamically create some type of javascript onload event that executes the Ajax function with the parameters I have submitted, but surely there must be a better way?
Ok, so the way that I solved this in the end was to do all the form POSTS with Ajax calls, then I could reload the same page through javascript on complete, rather than trying to reload the page from PHP somehow.

Parse a Json response array from server in javascript without loading the page

I am working on a webapp. I have a webpage that sends some data to the server via form tag. The server returns a json array. I want to know how to parse that json array without loading
my page. The purpose is to keep my webpage as it is and load some values from json array to
some text fields below my form tag for further processing.
edit: I have tried some examples for reading from json array but how to prevent webpage realoading.
Please use Ajax for this. Ajax calls are done using Javascript as per your requirement. If you are using library like JQuery it is quite simple to use.
Link to JQuery - Get: http://api.jquery.com/jQuery.get/
One of the ideas to save you from changing anything in your existing code is handle onsubmit of the form. Send your get/post on submit via ajax and cancel the submit of the form.

Flow of Jsp -> Javascript webpage (Ajax?)

I am making a website but I get a bit lost programming dynamic sites.
The user needs to enter x (inside a textbox), click submit, process in java (serverside) and present outcome as a report to the user (using javascript).
I'm at the moment using JSP to process the users input but now I need to pass the JSON code into the javascript. The javascript requires JSON data.
At the moment I have JSP which returns the necessary JSON code and the Javascript which works with hardcoded JSON code. I need to somehow store the returned JSON (from the JSP) in a variable and pass it to the Javascript. I have a vague understanding of AJAX - i'm just unsure if this is possible and how to link it all together.
Thank you.
Your JSP "page" can simply generate JSON directly. There's no reason the output from JSP has to be HTML. From the client, therefore, you POST to the server, the JSP runs, and the result (pure JSON from your JSP) is sent back to the client as the ajax response.
Sounds like the perfect place for AJAX - you can submit the request with javascript, and when it comes back process it further with javascript. Unless you want the page to refresh.
If you are using jQuery, you can look here to see how to implement it, should be relatively painless: http://api.jquery.com/jQuery.post/

Categories

Resources