gpt4 book ai didi

javascript - AJAX/Javascript 功能不起作用

转载 作者:行者123 更新时间:2023-12-02 19:16:19 24 4
gpt4 key购买 nike

嗨,我正在使用 ajax 调用一个名为 build_Array 的函数。此函数应分解 myString,即“调用 1-877-968-7762 启动您的休假。,1,0,through;您有资格获得 50% 的工资。,1,365,through;您的休假将是无薪的。, 1,0,之后;"分成由逗号分隔成二维数组的部分。但它不起作用。它表示数组的所有值都未定义。这是我在 ajax 中调用函数的地方...(它在 jsfiddle http://jsfiddle.net/ChaZz/3/ 中工作)

var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var myString = request.responseText;
myString = build_Array(myString);
document.getElementById('ajax').innerHTML = myString;
}
}

这是函数 build_Array...

function build_Array (myString) {
var mySplitResult = myString.split(';');
var myArray = new Array(mySplitResult.length);

//may need to get rid of -1
for(var i = 0; i < mySplitResult.length -1; i++){
myArray[i] = new Array(4);
var mySplitResult2 = mySplitResult[i].split(',');

for(var z = 0; z < mySplitResult2.length; z++) {
myArray[i][z] = mySplitResult2[z];
}
}
var final_message = myArray[1][1];
return final_message;
}

最佳答案

http://jsfiddle.net/ChaZz/5/

var myString = "Call 1-877-968-7762 to initiate your leave.,-30,0,through;You are eligible to receive 50% pay.,0,365,through;Your leave will be unpaid.,365,0,After;";

function build_Array (myString) {
var mySplitResult = myString.split(';');
var myArray = [];

for(var i = 0; i < mySplitResult.length; i++){
myArray[i] = [];
var mySplitResult2 = mySplitResult[i].split(',');

for(var z = 0; z < mySplitResult2.length; z++) {
myArray[i][z] = mySplitResult2[z];
}
}
var final_message = myArray[1][1];
return final_message;
}

console.log(build_Array(myString)); // 0

关于javascript - AJAX/Javascript 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13093959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com