[英]Jquery: Probably a syntax Issue in ajax() method - Value not getting sent
I'm able to dump value of the variable message in console . 我可以在console中转储可变消息的值。
But im not able to send it off in POST Request. 但是我无法在POST请求中发送它。
AJAX call: AJAX通话:
chat.throwmsg = function(message) {
if ($.trim(message).length != 0) {
console.log(message);
$.ajax({
url: 'ajax/chat.php',
type: 'post',
data: { method: 'throw', message: message} ,
success: function(data) {
chat.fetchmsgs();
$('textarea#entry').val('');
}
});
}
}
This maybe due to wrong syntax, but I've tried both single and double quotes, and combination as well . 这可能是由于语法错误造成的,但是我尝试了单引号和双引号以及组合。
With a wild assumption, you are not having any error messages in developer console and chat.php has a post handler forthese parameters 在一个疯狂的假设下,您在开发人员控制台中没有任何错误消息,并且chat.php具有一个后处理程序参数。
Since your data is JSON, please change the code as this way and have a try.. 由于您的数据是JSON,请以这种方式更改代码并尝试一下。
var temp={ method: 'throw', message: message};
var param=JSON.stringify(temp);
$.ajax({
url: 'ajax/chat.php',
type: 'post',
data: param ,
dataType: "json",
success: function(data) {
chat.fetchmsgs();
$('textarea#entry').val('');
}
});
查看代码后,我找不到任何限制与ajax请求一起发送的数据的问题,如果您遇到任何语法错误,则应在请求初始化之前警告您,但是我建议您在浏览器控制台的“网络”标签,并查看发送数据和请求(如果有),则可能需要检查在服务器端实现中获取发布数据的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.