我有一个 ajax POST,它将数据发送到 Controller 函数,该函数将字符串数组返回给 ajax 调用,作为 ajax 成功方法中的默认第一个参数。当我尝试使用返回的数据时,它不会让我将第一个元素打印到警告框中。怎么会?
即
$.ajax(
{
type: "POST",
url: "../Home/stringSplitFunct",
data: { 'parameter1': Input },
success: function (response)
{
alert(response[0]);
}
});
事实上,我认为它甚至不认为它是一个字符串数组。
最佳答案
您需要指定dataType
。阅读更多 here .
$.ajax({
type: "POST",
url: "../Home/stringSplitFunct",
data: { 'parameter1': Input },
dataType: 'json',
success: function (response)
{
alert(response[0]);
}
});
关于javascript - AJAX:如何使用返回的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21243285/