1

ページの読み込み時にアクションを読み込みたい。

struts2 と jquery を使用しています。

commentOn 要素のすべてのコメントを取得したい。

ページの読み込みの場合、commentOn 値を fetchallcomments アクションに送信しています。読み込まれたコンテンツは、div gameComments に表示される必要があります。

<script>
    $(document).ready(function() {
        $(".gameComments").load("fetchallcomments", {
            commentOn: '<s:property value="id"/>' 
        });
    });
</script>

<body>
  <div class="gameComments">
  </div>
</body>

struts.xml で

<action name="fetchallcomments" class="comment.action.commentAction" method="fetchAll">
        <result name="success">/pages/others/ajaxcomments.jsp</result>
        <result name="input">/pages/others/playGames.jsp</result>
        <result name="login">/pages/login.jsp</result>
    </action>

アクチンクラスで

public class commentAction extends ActionSupport {

private String commentOn;
private String comment;
private ArrayList commentList;
getter and setters;

private String fetchAll() {

System.out.println(" commentOn " + getCommentOn());
Map m = new HashMap();

m.put("commentOn", getCommentOn());
Map ab = cb.fetchAll(m);
    status = (String) ab.get("status");
    if (status.equalsIgnoreCase("success")) {
        setCommentList((ArrayList) ab.get("commentList"));
        return SUCCESS;
    } else {
        addActionError("Sorry not able to fetch");
        return INPUT;
    }

}

}

ajaxcomments.jsp 内

<body>
    <s:iterator var="cat" value="CommentList">
         <s:property value="comment"/>
    </s:iterator>
<body>
4

1 に答える 1

1

あなたがしていることは間違っています。

$(document).ready(function() {
        $(".gameComments").load("file/path/to/the/file.php #divYouAreGonnaFetch",{
            commentOn: '<s:property value="id"/>' 
        });
    });

上記を試して、私に知らせてください。

.load( url [, data] [, complete(responseText, textStatus, XMLHttpRequest)] )

続きを読む

于 2012-12-18T07:24:55.110 に答える