Question

When performing a getJSON function, and I want to send some data to the server (I'm using a java Stripes framework), I was jut wondering, what datatype will it be?

e.g.

$.getJSON("/tictactoe/get_next_move",
   {board: displayedBoardArray},
   function(data) {
   var json = data;
}

What is the type of board if I want to retrieve it? displayedBoardArray is a var Array type. After retrieving the board type and printing it out like this:

private String[] board;

public String[] getBoard(){
    return board;
}

public void setBoard(String[]board){
    this.board = board;
}

...
System.out.println("board: " +board); //This retrieved a null
...

Is String[] a wrong datatype?

Was it helpful?

Solution

I'm going to chime in only because better people than me have not yet. Nothing gets good answers quicker than someone trying to one-up someone else. ;-)

What form does displayedBoardArray take? If it's actually an object containing key:value pairs, it should come into the server as a series of GET parameters and values. If it's just a raw JavaScript array, I don't think you can do that.

In general, though, once you are sending valid data to the server, it will come in as GET parameter(s) which you will grab using some sort of method. I couldn't say if your Stripes method is doing that. Again, generally speaking, you can theoretically have a method that will create an array, or a method that will create a string (with comma separations or similar). I guess it depends on the method that's grabbing the GET parameter values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top