【发布时间】:2020-09-13 01:54:02
【问题描述】:
我有这个 AJAX post 请求:
$.ajax({
type: 'post',
url: 'gestioneFotografie.php', //The current page
contentType: "application/json; charset=utf-8",
data: {
lat: lat,
lng: lng
},
dataType: 'text',
success: function(data) {
alert(data);
}
});
【问题讨论】:
-
那么你在回帖中返回了什么?
-
所以你的 php 文件返回了一个完整的 html 文档,这就是警报显示的内容。如果您不想要 html,请不要返回 html。
-
发帖页面和回复页面是一样的(cf.comment "//The current page")。我想PHP代码中一定有一个错误。它应该优先处理 AJAX
POST请求(如果有),然后退出并返回文本字符串(无 HTML 输出)。 -
如果你发布 JSON,你需要
JSON.stringify()data -
@Éric jQuery 只会将对象字符串化为
application/x-www-form-urlencoded格式。 OP 已指定application/json的内容类型,因此他们应该使用data: JSON.stringify({ lat, lng })
标签: jquery json ajax post alert