php - 没有警报消息,Ajax 成功不起作用
问题描述
没有警报消息,Ajax 成功不起作用。控制台中没有错误。
$.ajax({
url: "<?php echo base_url(); ?>Sensor/ConnectionTypeList",
type: "POST",
data: {'model_id': model_id},
dataType: 'json',
success: function (data) {
console.log(data); //not runnig
//alert(''running);
if (document.getElementById("offset")) {
document.getElementById("offset").value = data[0].offset;
}
if (document.getElementById("multiplier")) {
document.getElementById("multiplier").value = data[0].multiplier;
}
if (document.getElementById("func")) {
document.getElementById("func").value = data[0].func;
}
if (document.getElementById("meas_command")) {
document.getElementById("meas_command").value = data[0].meas_command;
}
if (document.getElementById("read_command")) {
document.getElementById("read_command").value = data[0].read_command;
}
},
error: function () {
alert('Error.');
}
});
解决方案
结果类型是 JSON 吗?在这种情况下,您需要解析返回的结果才能使用它,如下所示:
$.ajax({
url: "<?php echo base_url(); ?>Sensor/ConnectionTypeList",
type: "POST",
data: {'model_id': model_id},
dataType: 'json',
success: function (data) {
data = JSON.parse(data);
console.log('>>', data);
...
我总是在 a 中使用“>>”(或类似的东西)console.log
来确保您始终看到控制台消息,即使结果为空。检查控制台日志以查看结果及其类型。
推荐阅读
- ios - Vuetify 数据表在 Safari 中呈现问题
- html - 动画延迟问题
- python - 是否可以从 Python 运行 Falcon 应用程序?
- android - 如何为 wrap_content 设置动画?
- java - 尝试将文件上传到 Amazon S3 时返回错误代码 400
- azure - Azure:从 MySQL 数据库创建 O365 事件
- docker - Docker In Docker IN Docker Compose(网络问题)
- r - 如何仅使用一定数量的值逐行删除数据
- ruby-on-rails - 未定义的方法“client_path”
- ios - Objective C中的TCP套接字设置