pageEncoding="UTF-8"%>
Insert title herevar myAjaxObject;
function AjaxTransferText() {
var BigText = document.getElementById("BigText").value;
var AjaxTransferObjectRef = new AjaxTransferObject("username", "password",
10, BigText);
var JSONString = JSON.stringify(AjaxTransferObjectRef);
if(window.ActiveXObject){
myAjaxObject = new ActiveXObject("Microsoft.XMLHTTP");
}else {
myAjaxObject = new XMLHttpRequest();
}
var urlString = "jsonString=" + JSONString;
alert(urlString);
myAjaxObject.open("POST", "getJSON.action"+"?timestamp" + new
Date().getTime(),true);
myAjaxObject.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded")
myAjaxObject.send(urlString);
}
function AjaxTransferObject(username, password, age, BigText){
this.username = username;
this.password = password;
this.age = age;
this.BigText = BigText;
}
function AjaxTransferTextByget(){
var BigText = document.getElementById("BigText").value;
var AjaxTransferObjectRef = new AjaxTransferObject("username", "password",
10, BigText);
var JSONString = JSON.stringify(AjaxTransferObjectRef);
if(window.ActiveXObject){
myAjaxObject = new ActiveXObject("Microsoft.XMLHTTP");
}else {
myAjaxObject = new XMLHttpRequest();
}
var urlString = "jsonString=" + JSONString;
alert(urlString);
myAjaxObject.open("POST", "getJSON.action"+urlString,true);
myAjaxObject.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded")
}
Action代码如下:
package controller;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONObject;
public class GetJSON extends ActionSupport{
private String jsonString;
public String getJsonString(){
return this.jsonString;
}
public void setJsonString(String jsonString){
this.jsonString = jsonString;
}
@Override
public String execute() throws Exception {
System.out.println(jsonString);
JSONObject json = JSONObject.fromObject(jsonString);
System.out.println("username=" + json.get("username"));
System.out.println("password=" + json.get("password"));
System.out.println("age=" + json.get("age"));
System.out.println("BigText=" + json.get("BigText"));
return null;
}
}