2 qaz2wsc qaz2wsc 于 2014.01.02 17:18 提问

ajax怎么获取返回值的方法啊?

$.ajax({
type:"Post",
url: "AjaxServerInfo.aspx",
data:'token=checkLink&sername='+$("#txtsername").val(),
success: function (data) {
return data;
}
});
怎么返回,data的值?点解,无法返回,求科普~

3个回答

arse_kingdom
arse_kingdom   2014.01.02 18:00

JS:

$("#selectInfo").click(function(){
var params = $("#partiesinfo").serialize(); //预先准备向后台发送数据

$("#message3").show();

$("#message2").hide();
$("#message").hide();
$("#message1").hide();

$("#content3").html("");
$.ajax({ //使用ajax与服务器异步交互
url:"proDial!selectFromConditions1.action?tm"+new Date().getTime(), //后面加时间戳,防止IE辨认相同的url,只从缓存拿数据
type:"POST",

data:params, //向后台发送的form表单中的数据
dataType:"json", //接收返回的数据方式为json

error:function(){alert("交互失败")}, //错误提示

success:function(data){ //data为交互成功后,后台返回的数据

$.each(data.partieInfolist,function(i,value){ //便利 data.billinglist

$("#content3").append("

"+value.id+""+value.confid+""+value.phone+""+value.isDialoutedIDD+""+value.connTime+""+value.disConnTime+""+value.duration+""+value.dialoutRoute+""+value.countryCode+""+value.countryName+""+value.partyID+""+value.partyName+"");
});
}});
});

java`package com.qs.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import SessionFactory.Confs;
import SessionFactory.Parties;

import com.opensymphony.xwork2.ActionSupport;
import com.qs.dao.DaoManager;

public class proDail extends ActionSupport {

private Confs confs;
private Parties parties;
private List<Confs> confslist;      //使用josn返回List对象
private List<Parties> partieslist;      //使用josn返回List对象
private List<Confs> billinglist;        //使用josn返回List对象 billingcode 模糊查询
private List<Parties> partieInfolist;

public Confs getConfs() {
    return confs;
}

public void setConfs(Confs confs) {
    this.confs = confs;
}

public Parties getParties() {
    return parties;
}

public void setParties(Parties parties) {
    this.parties = parties;
}

public List<Confs> getBillinglist() {
    return billinglist;
}

public void setBillinglist(List<Confs> billinglist) {
    this.billinglist = billinglist;
}

public List<Confs> getConfslist() {
    return confslist;
}

public void setConfslist(List<Confs> confslist) {
    this.confslist = confslist;
}

public List<Parties> getPartieslist() {
    return partieslist;
}

public void setPartieslist(List<Parties> partieslist) {
    this.partieslist = partieslist;
}

public List<Parties> getPartieInfolist() {
    return partieInfolist;
}

public void setPartieInfolist(List<Parties> partieInfolist) {
    this.partieInfolist = partieInfolist;
}




public String selectAll() throws IOException{
    DaoManager manager=new DaoManager();
    HashMap<String,List> map=manager.getSelectAll();
    confslist=map.get("confsList");
    partieslist=map.get("partiesList");
    return "list";
}

public String selectFromConditions() throws IOException{
    DaoManager manager=new DaoManager();
    HashMap<String,List> map=manager.getSelectFromConditions(confs.getBillingCode());
    billinglist=map.get("billingList");
    return "billingcode";
}

public String selectFromConditions1() throws IOException{
    DaoManager manager=new DaoManager();
    HashMap<String,List> map=manager.getSelectFromConditions1(parties);
    partieInfolist=map.get("partieInfoList");
    return "partiesinfo";
}

}
`

好久之前写的代码,希望能帮助你

u013360327
u013360327   2014.01.02 17:27

怎麽是乱码啊!看不懂耶!

yjhkhnuje
yjhkhnuje   2014.01.02 19:01

用request中的wirte方法返回回去

ac923
ac923 具体怎么写
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!