By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Perform one AJAX request one after another.

P: 8
I'm new to the whole concept of using AJAX in my PHP scripts and I have stone-walled.

What I am looking to do is this;

Once the page loads, my AJAX script will start to send data to my server so that it can verify the data, after it recieves a response from my server of either a "0" or a "1", it then goes on to send another request to my server and wait for a response, it'll carry on doing this until theres no more data to verify.

The data that the script will send to my server will probably be generated by PHP and look something similar to this;

Expand|Select|Wrap|Line Numbers
  1. var request1=new Array("127.0.0.1", "80");
  2. var request2=new Array("127.0.0.1", "80");
  3. var request3=new Array("127.0.0.1", "80");
  4.  
My problem is this -

I have no knowledge of AJAX, I have absolutely no clue how to do what I proposed, but without it, my script will never work.

Here's how the page will work;

PHP generates all the variables
AJAX 'locates' those variables and begins to parse them one by one, sending the data to my PHP script using AJAX using the GET type, my server will respond to AJAX and produce a number of either 1 or 0 (I can code all the PHP aspects of this)
After AJAX recieves the response from my server, it'll do some javascript code to start changing divs and whatnot (I can also do this).

My issue is the AJAX. I've probably repeated myself and missed out key information, if I have please tell me and I'll try fix it.

All help/suggestions are appreciated, I've been searching all over the place for two days and requesting help with this is my last resort.
Feb 2 '12 #1
Share this Question
Share on Google+
5 Replies


Rabbit
Expert Mod 10K+
P: 12,430
Show us the code where you make the AJAX request.
Feb 2 '12 #2

P: 8
I'm sorry I didn't clarify myself enough...

I have no AJAX code, I have no knowledge of AJAX, I posted here simply for a step in the right direction, or if someone is kind enough, some code I could work from.

I basically need -

Some partial code that tells me
A) How to tell AJAX what data to send to the server
B) How to tell AJAX to parse the data individually, sending the data one by one.
Feb 2 '12 #3

Rabbit
Expert Mod 10K+
P: 12,430
Just to be clear, AJAX is nothing more than using javascript to request a page. To answer A, look at the tutorial at W3Schools. As for B, you send data back however you want, then you parse it. How you want to do that is up to you.
Feb 2 '12 #4

P: 8
Oh okay, I seem to have overused the term AJAX, I've been reading multiple tutorials on AJAX/Javascript and can't find a single one that teaches me how to;

Send one piece of data to my server, recieve a response and then send the next piece of data, this would loop until all the data has received a response from the server.

Do you have any idea of how to do the above task? The data are just stored in simple variables such as "data1, data2, data3" I'm really mind-boggled by what I'm asking for and I'm sorry to ask for so much from you.

If the way I am typing confuses you, please tell me and I'll try make it easier to understand, its really hard to explain what I am asking for.
Feb 2 '12 #5

Rabbit
Expert Mod 10K+
P: 12,430
First make one request that sends back information. The tutorial I linked above shows you how to do that. After you successfully get back one request, you can work on the second piece, continual requests.
Feb 2 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.