last day (15 days later) » 

5:12 PM
Hi
 
Hi. Thank you for joining
 
i l join back in 15 mins.. if that's ok
 
Sure. No worries.
I'll wait for you.
 
cool
 
5:27 PM
Hello
 
5:57 PM
HI
sry i got caught up in some other work..
if it's not too late.. can we talk about your issue ?
 
6:16 PM
Hi
Are you there?
I changed the call to :
$(document).ready(function() {
                $('#submitdata').click(function(event) {
                    event.preventDefault();
                    $.ajax( {
                       url: 'http://localhost:8081/Football/insert',
                       data: {
                           nameField : $('#nameField').val(),
                           goalField : $('#goalField').val(),
                           passField : $('#passField').val()
                       },
                       type: 'GET'
It is working now.
I am new to AJAX. Wanted to talk about good practices in AJAX.
Do we need to take any precautions while working with AJAX?
 
hi
 
Hello
 
its cool that you solved your issue..
I'm not an Ajax expert but I've been using it for a while..
wat exactly do you want to know ?
 
What I understand from $.ajax() is that AJAX starts and ends at this function! Is there anything more that I can look upto?
Requesting to and from a webpage could be done by calling $.ajax(). What else can AJAX do? Do we need to take some precautions while using AJAX?
 
did you check the official docs of jQuery ? $.ajax() has two options to work with server responses - one is using success property in Ajax definition where in you pass an anonymous function and other one is done() method chaining on $.ajax()
both the options take anonymous function which will be invoked once your http response is completely received and parsed to the type you're expecting..
 
6:27 PM
Yes, but I guess both are meant for the same purpose.
 
yup.. success is old way but done() is about adding promises to jQuery lib.. both are functionally same.. so need not bother about which one you use
 
What if multiple AJAX requests are being sent to the server at the same time? Will it lead to any issue?
 
Ajax can do lot of things that any synchronous request can do.. It's basically the same HttpRequest without refreshing the page,, in fact if you notice there's no way to differentiate between Ajax call and form submit on server side.. of course jQuery adds a custom header in Ajax calls but it's just a practice.. there's no hard rule that all libraries and browsers should do that
nope.. it wont cause any issue until and unless your code on server side has some issue with duplicate requests..
for example, lets say there's an Add button that is supposed to insert some data in to database, if your not showing any indication to the user, user might click the button again and data might be inserted into database twice.. that's why we usually disable the button temporarily show some processing icon and then update the status once the ajax response is received
 
I see.
If I want to get data from a servlet, how could I do that?
By using
success : function( json ) {} ?
 
yes.. the function you're passing to success takes 3 parameters.. xhr - the actual XHMHttpRequest object used to fire the ajax call, data - server response received and parsed into your desired type like html/JSON , (3) response String -- status code of response as string something like "200 OK"
 
6:41 PM
Thank you. I appreciate your help.
I must leave now.
 
ok bye.. Happy Learning :)
 

last day (15 days later) »