我需要发布一些参数数据。这应该是一个不带json对象的简单的裸字符串。我这样做了,我成功了,但参数不是保存。
var offerMsg = $('.js-offerMsg').val();
$.post(url, ("message", offerMsg));
有人能帮上忙吗?
发布于 2014-06-07 13:41:26
您应该按如下方式进行调用:
$.post(url, {message: offerMsg});
这将发送一个表单编码的帖子:
POST /path HTTP 1.1
Host: example.com
Content-Length: 10
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
message=hi
如果要发送非表单编码的内容,则不能使用$.post
,因为不能覆盖contentType
参数,即使在发送原始字符串时也是如此。你需要这样做:
$.ajax({
url: url,
type: "POST",
data: offerMsg,
contentType: "text/plain; charset=UTF-8"
});
这将导致:
POST /path HTTP 1.1
Host: example.com
Content-Length: 2
Content-Type: text/plain; charset=UTF-8
hi
https://stackoverflow.com/questions/24097656
复制