How do I collect a crossrider post with node js or php.
Here is the post:
appAPI.ready(function($) {
// Posting data using a JSON object
appAPI.request.post({
url: 'http://example.com',
// Data to post
postData: {hello:123, name:'john'},
onSuccess: function(response) {
alert("Succeeded in posting data");
alert(response);
},
onFailure: function(httpCode) {
alert('Failed to retrieve content. (HTTP Code:' + httpCode + ')');
},
additionalRequestHeaders: {
myHeader: 'value'
},
contentType: 'application/json'
});
How do I retrieve this using nodejs? Also do I just use a normal
$var = $_post
in php or do i have to use Curl? If I can use the above syntax how do I specify what the POST is called? with a form I'd just use $_post["formName"] but because this is not a form what do I do?
Just do print_r($_POST); and you will see the variables that your server got.
You will be able to look on the response via console.log(response); or check the network tab of the chrome background page, the calls are going to the server throw there.
Correction: Now i see the request on the developer tools for the page, not the extension's background page. Its easier to debug this.
appAPI.ready(function($) {
var data1 = "Mydata1";
var data2 = "Mydata2";
appAPI.browserAction.onClick(function() {
appAPI.request.post({
url: 'http://www.example.com/Ext.php',
postData: 'data1='+ data1 +'&data2='+ data2,
onSuccess: function(response) {
alert("Succeeded in posting data");
//alert(response);
},
onFailure: function(httpCode) {
alert('in posting data. (HTTP Code:' + httpCode + ')');
},
additionalRequestHeaders: {
myHeader: 'value'
},
// contentType: 'application/json'
contentType: 'application/x-www-form-urlencoded'
});
}); });
Then, in the Ext.php file grab the post data using $_POST["data1"] and $_POST["data2"]
Sample code for $_POST[]: http://www.w3schools.com/php/php_post.asp