I'm not sure if I'm approaching this the correct way but I'm trying to send a small amount of data to the server and receive a couple of strings back. Because of the way the server CMS works the data is most easily sent in the URL path so I have no need to send any additional 'data'. For example :
var url = '/footnotes/cleartile/'+nid+'/'+tid+'/'+side;
var mydata = 'This serves no purpose';
jQuery.post(url, mydata, function(data) {
console.log("Data Loaded: " + data);
});
Is jQuery.post() the correct mechanism for this type of munication ? And if so, what should I pass in the data parameter when nothing is necessary ?
I'm not sure if I'm approaching this the correct way but I'm trying to send a small amount of data to the server and receive a couple of strings back. Because of the way the server CMS works the data is most easily sent in the URL path so I have no need to send any additional 'data'. For example :
var url = '/footnotes/cleartile/'+nid+'/'+tid+'/'+side;
var mydata = 'This serves no purpose';
jQuery.post(url, mydata, function(data) {
console.log("Data Loaded: " + data);
});
Is jQuery.post() the correct mechanism for this type of munication ? And if so, what should I pass in the data parameter when nothing is necessary ?
Share Improve this question asked Jun 28, 2014 at 14:10 elbelb 1771 silver badge8 bronze badges3 Answers
Reset to default 7To keep the same function I would use this:
var url = '/footnotes/cleartile/'+nid+'/'+tid+'/'+side;
jQuery.post(url, {} , function(data) {
// The data here represents the answer from the server
console.log("Data Loaded: " + data);
});
or
jQuery.post(url, function(data) {
// The data here represents the answer from the server
console.log("Data Loaded: " + data);
});
$.post
doesn't require the data
argument at all, it's listed as optional. You can just leave it out:
var url = '/footnotes/cleartile/'+nid+'/'+tid+'/'+side;
jQuery.post(url, function(data) {
console.log("Data Loaded: " + data);
});
You probably want to use jQuery.get
in this case (if the server does accept a GET
rather than only a POST
, which is most certainly the case here).