当前位置: 代码迷 >> Java Web开发 >> jQuery $.get()有关问题
  详细解决方案

jQuery $.get()有关问题

热度:3747   发布时间:2013-02-25 21:20:00.0
jQuery $.get()问题
今天准备写个ajax效果,就用jQuery的$.get(),方法发送请求,结果死也没进到Action中,帮忙看看是怎么回事

js文件:
JScript code
    <script type="text/javascript" src="util/jquery.js"></script>    <script type="text/javascript">        function findRegion(){            var Sel = $("#selCritically");            var criticrallyID=Sel.val();            alert(criticrallyID);            $.get("region.do");        }    </script>


Struts-conf.xml文件:
XML code
  <action      parameter="op"      path="/region"      type="com.dy.MyLy.struts.action.RegionAction" />

Action文件
Java code
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package com.dy.MyLy.struts.action;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Set;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction;import com.dy.MyLy.biz.inface.ICriticallyBiz;import com.dy.MyLy.biz.inface.IRegionBiz;import com.dy.MyLy.hb.entity.Critically;import com.dy.MyLy.hb.entity.Region;/** * MyEclipse Struts Creation date: 11-16-2009 *  * XDoclet definition: *  * @struts.action parameter="op" validate="true" */public class RegionAction extends DispatchAction {    private ICriticallyBiz criticallyBiz;    /*     * Generated Methods     */    public void setCriticallyBiz(ICriticallyBiz criticallyBiz) {        this.criticallyBiz = criticallyBiz;    }    /**     * Method execute     *      * @param mapping     * @param form     * @param request     * @param response     * @return ActionForward     */    public ActionForward execute(ActionMapping mapping,            ActionForm form, HttpServletRequest request,            HttpServletResponse response) {        String criticallyId = request.getParameter("id");        Critically c = criticallyBiz.findByID(Integer.parseInt(criticallyId));        Set regionSet = c.getRegions();        Iterator iter = regionSet.iterator();        List regionList = new ArrayList();        while (iter.hasNext()) {            Region g = (Region)iter.next();            regionList.add(g);        }        request.setAttribute("regionAList", regionList);        return null;    }}

就是死活进不去,Action也加../了,$.post方法也用过还是进不去 = =!


------解决方案--------------------------------------------------------
$.get("/项目名/region.do");

或者在meta里定义base.
------解决方案--------------------------------------------------------
用firefox+firebug看看是否调用了请求以及请求的路径啥的是否正确
------解决方案--------------------------------------------------------
使用dispatchaction需要指定方法的,
最好在action中不要命名为execute了。方法名为:DoDet
$.get("region.do?op=DoDet");

------解决方案--------------------------------------------------------
就是,你action是dispacherAction,没有添加参数名
  相关解决方案