我有一些使用jQuery调用$.post()
的JavaScript代码。我想向该函数发送一个字符串参数,但是我的尝试没有成功。我尝试了在另一篇文章中看到的此函数调用,但没有成功$.post(SavePoint, { data });
myTimer = (function(ctx) {
$.post(getPoint).done(function(xml) {
parseXml(xml);
var lon = (parseFloat($xml.find("lon").text()) + 180) * (screen.height / 360);
var lat = (parseFloat($xml.find("lat").text()) + 90) * (screen.width / 180);
draw(ctx, rout, lat, lon);
if (recordTime <= 0 && recordTime > -0.2) {
$.post(SaveToFile);
isSaveNeeded = "false";
}
var isSaveNeeded = document.getElementById("isSaveNeeded").value;
if (isSaveNeeded == "true") {
var latS = parseFloat($xml.find("lat").text());
var lonS = parseFloat($xml.find("lon").text());
var rudderS = parseFloat($xml.find("rudder").text());
var throttleS = parseFloat($xml.find("throttle").text());
var data = latS + "," + lonS + "," + rudderS + "," + throttleS + ",";
alert(data);
$.post(SavePoint, {
data
}); //This func call doesn't work..
alert(data);
recordTime -= 0.25;
}
});
});
setInterval(function() {
myTimer(ctx);
}, 1000 / rate);
答案 0 :(得分:0)
$.post
将第二个参数作为对象而不是字符串,我认为您的data
是字符串,请从下面引用。在SavePoint
端点中,您将选通data
参数。
var data = latS + "," + lonS + "," + rudderS + "," + throttleS + ",";
alert(data);
$.post(SavePoint, { data: data },
function(returnedData){
console.log(returnedData);
}).fail(function(){
console.log("error");
});