Forum Moderators: open

Message Too Old, No Replies

Pushover App With Ajax

         

almo136

5:37 pm on Sep 14, 2020 (gmt 0)

10+ Year Member



I am using [pushover.net...] to send notifications to a smartphone from our website.

This works fine when using php i.e.:

<?php
//pushover notification
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
CURLOPT_POSTFIELDS => array(
"token" => "XXX",
"user" => "XXX",
"sound" => "cashregister",
"message" => "Test Message",
),
CURLOPT_SAFE_UPLOAD => true,
//Set to false for testing
CURLOPT_RETURNTRANSFER => true,
));
curl_exec($ch);
curl_close($ch);
}
?>

I now need to send a notification that contains some browser info so I need to send this client side. Is there a way to send this via ajax? The user and token keys would need to remain private so I am assuming the ajax would need to access a php script? I am not too familiar with ajax so don't know how to do this.

Pushover API info can be found here:
[pushover.net...]

NickMNS

6:12 pm on Sep 14, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I now need to send a notification that contains some browser info so I need to send this client side.

You can't/shouldn't send this client side. What you need to do is have the client side send you (the server) what ever information needs to be sent. (to be clear communication between client and server would be via http request) and then send that using the api from the server. To do this gather the information needed in a form and then send the info via a POST request to the server, then on receipt of the form send the text message.

I assume that you are sending information from one user to another. Is the user who's information is being gathered aware of what is being sent? Also, remember that text messages are not encrypted, so be carefully of what you send and to whom.

Edit: I presumed that you are sending notification over SMS, is that the case? Or are you using push notifications?

almo136

6:27 pm on Sep 14, 2020 (gmt 0)

10+ Year Member



We are sending visitor analytics. We have in our T&Cs that we collect analytics. In this case we want to send browser info so it isn’t sensitive info. It is the same as info we already collect in Analytics.

We need to send this silently when the page loads so a form wouldn’t work. Can this be sent to the server in the background using Ajax?

NickMNS

8:19 pm on Sep 14, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



We need to send this silently when the page loads so a form wouldn’t work. Can this be sent to the server in the background using Ajax?

Using a form does not mean that the user must fill in a form and press submit. Rather it means that the data you send is stored in a form object, which can then be sent asynchronously (AJAX).
[developer.mozilla.org...]