我不确定我是否以正确的方式处理这个问题,但我正在尝试向服务器发送少量数据并接收几个字符串。由于服务器 CMS 的工作方式,数据最容易在 URL 路径中发送,因此我不需要发送任何额外的“数据”。例如:
var url = '/footnotes/cleartile/'+nid+'/'+tid+'/'+side;
var mydata = 'This serves no purpose';
jQuery.post(url, mydata, function(data) {
console.log("Data Loaded: " + data);
});
jQuery.post() 是这种类型通信的正确机制吗?如果是这样,当没有必要时我应该在数据参数中传递什么?
最佳答案
为了保持相同的功能,我会使用这个:
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);
});
或
jQuery.post(url, function(data) {
// The data here represents the answer from the server
console.log("Data Loaded: " + data);
});
关于javascript - 如何在没有数据发送的情况下使用 jQuery.post(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467638/