I would like to connect my Chrome Extension to my server, and send data back and forth. In particular, when the user clicks a button on the extension when he’s navigating a certain URL, the server checks its database to see how many times that URL has been clicked, increment the count, and send the new count back to the user.
I know that sending the data to the server is possible with an AJAX request, but what about getting the data back from the server?
I think, you may use AJAX for getting updated count in a straightforward manner. For example (with jQuery):
So you can “send” new info as parameters of GET request, and get required information from server as http-response. The type of the data used to transfer the count is up to you. For example, this can be
json(jQuery provides a shorthand methodgetJSON, which does the same customizedajaxcall).If you don’t want GET, you may use POST and specify data as follows: