2

I'm working on Android GCM console that shown all register users and I can send Individual or mass message. My individual message works but cannot handle Ajax to send a mass message. This is my UI code:

$(document).ready(function(){

       $(".send_all").click( function()
       {
            var msg = $(this).parent().find('.txt_message').val();

            $.ajax({
            url: "send_mass_message.php",
            type: 'GET',
            data: {"message": msg},
            beforeSend: function() {

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

UPDATED:

I tested the send_mass_message.php with passing parameters with URL and it works. so my problem is with Ajax part.

send_mass_message.php:

<?php

    if (isset($_GET["message"])) {

        $message = $_GET["message"];


        include_once 'config.php';
        include_once 'db_functions.php';

        $db = new DB_Functions();
        $users = $db->getPURCHASEDUsers();
        $count = mysql_num_rows($users);

        $message = array("message" => $message);
        //echo $message;

        include_once 'GCM.php';
        $gcm = new GCM();

         while($row = mysql_fetch_array($users)){

            $regId = $row["gcm_regid"];
            $registatoin_ids = array($regId);
            $result = $gcm->send_notification($registatoin_ids, $message);
            echo $result;

        }


}

?>
Mahdi
  • 6,139
  • 9
  • 57
  • 109
  • What's contained in the msg variable? Is it a json string, an array or just a normal string? If it's an actual array, you might want to look here: [Convert js Array()](http://stackoverflow.com/questions/713884/convert-js-array-to-json-object-for-use-with-jquery-ajax) – Osuwariboy Jun 26 '15 at 18:48
  • @Osuwariboy, it's just a string. – Mahdi Jun 26 '15 at 19:52
  • Have you made any debug attempts at all? Can you verify AJAX call is sending data correctly? Where is script behavior varying from what you expect? Are you getting errors in javascript console or server-side logs? You have a lot of code referenced here that we don't have access to (like `DB_Functions()`, `GCM()`, etc.) and it is pretty much impossible to help you sort out the problem without more information on what is going wrong. – Mike Brant Jun 26 '15 at 20:45
  • @MikeBrant DB_Functions() and GCM() work currectly cause they work on single GCM message send. I tested the send_mass_message.php with url and seems that the first problem is with this part. maybe Ajax is working well. I post individual send message.php tthat works in right well. so plz compare it with send_mass_message.php – Mahdi Jun 26 '15 at 21:35
  • @Kenji You said "I tested the send_mass_message.php with passing parameters with URL and it not works". Explain what is not working. What result do you get? What result do you expect? Have you tried tracing key variable values throughout code execution to see where behavior differs from what you expect? The way you have asked the question, you are not going to get answers, because we have no idea what the variable values in play are and where your code behavior differs from what you expect. – Mike Brant Jun 29 '15 at 14:16
  • @MikeBrant I updated the question by pussing GCM.php . I would like to do what hapens in individual message in a loop for sending message for all records of table. – Mahdi Jun 30 '15 at 07:34
  • @Kenji Just posting more code is not narrowing down the problem for us, it is making the problem broader. What have you done to narrow down the issue? – Mike Brant Jun 30 '15 at 19:13
  • @MikeBrant question updated. – Mahdi Aug 04 '15 at 06:42

0 Answers0