javascript - 如何设置 foreach jQuery JSON CSV

标签 javascript json jquery foreach

我有一个 jquery ajax 请求如下;

$.ajax({
        type: 'POST',
        url: 'ajax.php',
        dataType: 'json',
        cache: false,
        success: function(result) {
        alert (result);
        },
});

返回的 result 是 JSON 格式的。为了查看数据,我提醒了它,如下所示;

img1.jpg,img2.jpg,img3.jpg,img4.jpg

php 文件如下;

<?php
$array = array("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
echo json_encode($array);
?>

回声;

["img1.jpg","img2.jpg","img3.jpg","img4.jpg"]

我想为每个文件名提醒 filename。我该怎么做?

最佳答案

JSON 不是 CSV。这应该是一个错误。如果您正在接收 CSV,请不要说 dataType: 'json',将其作为文本接收,然后自行解析:

var fields = result.split('/');
$.each(fields, function(fieldNo, field) {
  alert(field);
});

如果是 JSON,则编辑您的问题并进行澄清。

关于javascript - 如何设置 foreach jQuery JSON CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562330/

相关文章:

javascript - KnockoutJS - 根据另一个菜单中的选择设置选择菜单

android - GET 请求 JSONObject android

javascript - 未捕获的类型不匹配错误 : Failed to execute 'drawImage' on 'CanvasRenderingContext2D'

javascript - 数据表 - 如何更改动态更改的单元格的背景和文本颜色?

javascript - 在 inIonic 中使用范围 slider 显示数字时出现问题

javascript - 将插值表达式传递到 Angular 指令中

javascript - 如何只触发一次服务器发送的事件?

json - 正则表达式:是否可以在捕获组内进行替换?

javascript - JSON 内的数组收到空

php - jQuery Tablesorter 不适用于使用 php 生成的表