在php中使用ajax发送多个请求

I am trying to send Push Notifications to android devices using a php script. This works fine if i send it to one device each time, but i have more than 1000 devices and want to send it to all of them at one go. I tried using a loop but it's not working.

<script type="text/javascript"> 
            $(document).ready(function(){ 

            }); 

            function sendToAll(totalUsers){

                for(var i=0;i<totalUsers;i++)
                {
                    sendPushNotification(i);
                }

            }
            function sendPushNotification(id){ 
                var data = $('form#1').serialize(); 
                $('form#1').unbind('submit'); 
                $.ajax({ 
                    url: "send_message.php", 
                    type: 'GET', 
                    data: data, 
                    beforeSend: function() { 

                    }, 
                    success: function(data, textStatus, xhr) { 
                          $('.txt_message').val("");
                          $('.txt_excerpt').val("");    
                    }, 
                    error: function(xhr, textStatus, errorThrown) { 

                    } 
                }); 
                return false; 
            } 
        </script> 

This is my HTML form. $no_of_users variable contains the total rows fetched in the select query i.e. the total number of users in the table.

<form id="1" name="" method="post" onsubmit="return sendToAll('<?php echo $no_of_users; ?>')"> 
                                <label>Send Message to All the Users</label> 
                                <div class="clear"></div> 
                                <div class="send_container"> 
                                    <textarea rows="3" name="excerpt" cols="10" class="txt_excerpt" placeholder="Type excerpt here"></textarea>
                                    <textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Type message here"></textarea> 

                                    <input type="submit" class="send_btn" value="Send" onclick=""/> 

You should use asyncronous requisitions to make all at "same time", use this instruction on your ajax call:

async: true,

You want to push some message to approx. 1000 devices from server. And you want to initiate this with the form and script you presented in the question. But you must also think about the way how server will communicate with devices. There must be some way for you server to reach clients.

One way - instruct you clients to poll server for new messages every N seconds for example. This generates unnecessary traffic and loads the server.

Second way - to use websocket on clients and have server-side support for this. It can be not so trivial as it can appear to be

And one more way - is to use long polling.

Anyways - devices must be instructed in some way how can they receive push messages from server.