admin管理员组

文章数量:1399912

I'm fairly new to JavaScript and AJAX, but I'm trying to take an AJAX's requests' response text and split it into an array (the response text is ma separated). Here's the error I get:

Uncaught TypeError: object is not a function localhost:36 myrequest.onreadystatechange

Here's my code:

var currentpicid;
var currentcat;
var currentindex;
myrequest.onreadystatechange=function(){
    if (myrequest.readyState==4 && myrequest.status==200){ //request successful
        var infoarray = myrequest.responseText.split(',');
        currentpicid = infoarray(0);
        currentcat = "top";
        currentindex = index;

        document.getElementById("image").innerHTML=myrequest.responseText;
    }
}

Can anyone help me? I have verified that my PHP page is just outputting a ma separated list of values. Thanks!

I'm fairly new to JavaScript and AJAX, but I'm trying to take an AJAX's requests' response text and split it into an array (the response text is ma separated). Here's the error I get:

Uncaught TypeError: object is not a function localhost:36 myrequest.onreadystatechange

Here's my code:

var currentpicid;
var currentcat;
var currentindex;
myrequest.onreadystatechange=function(){
    if (myrequest.readyState==4 && myrequest.status==200){ //request successful
        var infoarray = myrequest.responseText.split(',');
        currentpicid = infoarray(0);
        currentcat = "top";
        currentindex = index;

        document.getElementById("image").innerHTML=myrequest.responseText;
    }
}

Can anyone help me? I have verified that my PHP page is just outputting a ma separated list of values. Thanks!

Share Improve this question asked Dec 7, 2012 at 4:04 DannyF247DannyF247 6384 gold badges15 silver badges35 bronze badges 1
  • Getting this same error in ES6 for: Array.prototype.filter(allChats, chat => chat['response'] != '') – Kristopher Noronha Commented Jan 31, 2021 at 3:10
Add a ment  | 

1 Answer 1

Reset to default 6

Instead of:

currentpicid = infoarray(0);

you need:

currentpicid = infoarray[0];

The parentheses are for function calls. Use square brackets for array indexes.

本文标签: javascriptError quotobject is not a functionquot with arrayStack Overflow