为什么我的表单没有在postAjaxData方法中被序列化?

时间:2014-06-02 21:41:52

标签: jquery ajax

我试图通过Ajax从jsp页面获取数据元素到控制器。但是我的表单没有在javascript文件的postAjaxData方法中进行序列化。 PL。建议。 感谢。

Jsp文件 -

<form name="caseListingForm" id="caseListingForm" method="post">
<table>
  <c:forEach var="individualCase" items="${caseList}"
        varStatus="counter">
        <tr>

            <td style="padding-right: 10px">case ${counter.count}:</td>
            <td>out.write ("hello " + ${individualCase.id } ); 
                <input name="case_id" type="hidden" value="${individualCase.id}" /> 
                <a href="#" onclick="showQuestionPage('showQuestion.html');">${individualCase.caseLearningObj} </a>
            </td>
        </tr>
    </c:forEach>
</table>
</form>

JS档案

function showQuestionPage(targetUrl){
postAjaxData(null,'content',targetUrl, 'caseListingForm',null, function(){
    alert('yes showQuestionPage');  

});

}

function processRedirect(data) {
if (data != null) {
    alert ('data ' + data);
    if (data.redirect != null){
        window.location = data.redirect;
    }
}
}


function postAjaxData(initiatingElement, targetElement, targetUrl, form, additionalParamMap, successCallback) {

var $targetElement = $('#' + targetElement);

var serializedFormData;

serializedFormData = $('#' + form).serialize();

alert('serializedFormData ' + serializedFormData); //serializedFormData - returns empty 

for (var j in additionalParamMap) {
    serializedFormData += "&" + j + "=" + additionalParamMap[j];
}


$.ajax({
    type: "POST",
    cache: false,
    data: serializedFormData,   
    url: targetUrl,

    success:  function (data){
        processRedirect(data);

        $targetElement.html(data);
        $targetElement.show();  
    },
    error: function(httpRequest, textStatus, errorThrown) { 
        alert("status=" + textStatus + ",error=" + errorThrown);
    }
});


}

0 个答案:

没有答案