我有一个屏幕,用户可以单击“添加运输点”按钮,这会弹出一个对话框,他们在其中输入信息,点击“添加”,这会进行 Ajax 调用,将运输点添加到数据库,然后关闭对话框并那么 ajax 调用的成功回调方法应该在运输点表中附加一个 tr。一切正常,除了 tr 没有被添加。
这是应该将行添加到其中的运输点表的 html。
<table id="shipPoints" class="ui-widget-content" width="697">
<thead>
<tr class="ui-widget-content" width="696">
<th class="ui-widget-header" width="395">
Shipping Points
</th>
<th class="ui-widget-header" width="300">
Remove
</th>
</tr>
</thead>
<tbody>
<c:forEach items="${shippingPoints}" var="shippingPoint">
<tr width="695">
<td with="395">
${shippingPoint.shippingPointsCity},
${shippingPoint.shippingPointsState}
</td>
<td width="300">
<INPUT type="checkbox" NAME="chk" value="${shippingPoint.shippingPointsId}" />
<INPUT type="hidden" NAME="shipPointId" VALUE="${shippingPoint.shippingPointsId}" />
</td>
</tr>
</c:forEach>
</tbody>
</table>
这是做这项工作的jquery。
function saveShippingPoint()
{
//alert("Before ajax call.");
$j.ajax(
{
url: "<portlet:resourceURL id='saveShippingPoint'/>" +
"?city=" + $j( "#city" ).val().toUpperCase() +
"&state=" + $j( "#state" ).val().toUpperCase() +
"&stateOther=" + $j( "#stateOther" ).val().toUpperCase() +
"&zip=" + $j( "#zip" ).val() +
"&product=" + $j( "#product" ).val().toUpperCase() ,
type: 'GET',
cache: false,
timeout: 30000,
success: function(data)
{
//alert("In success callback.");
$j("#shipPoints tr:last").after(
"<tr>"
+ "<td>"
+ city.val().toUpperCase()
+ ", "
+ state.val().toUpperCase()
+ "</td>"
+ "<td>"
+ "<INPUT type='checkbox' NAME='chk' VALUE='"+ data + "' />"
+ "<INPUT type='hidden' NAME='shipPointId' VALUE='"+ data + "' />"
+ "</td>"
+ "</tr>");
},
error: function()
{
alert("There was a problem adding the shipping point.");
}
});
//alert("Done with ajax call, about to return.");
return;
};
这是用于输入信息的对话框的代码。
<div id="dialog-form" title="Shipping Points">
<p class="validateTips">
Please include all vendor ship points by product group. If vendor
ships all products from one location input City, State, Zip Code
then select "All" for product group.
</p>
<fieldset>
<label font-family="Courier New" align="left" for="city">City</label>
<input maxlength=50 align="right" type="text" name="city" id="city"
class="text ui-corner-all" />
<br />
<label font-family="Courier New" align="left" for="state">State</label>
<select maxlength=6 align="right" name="state" id="state"
class="text ui-corner-all">
<option value="">Select State...</option>
<c:forEach items="${states}" var="state">
<option value="${state.fieldValue}">
${state.fieldDescription}
</option>
</c:forEach>
</select>
<br />
<label font-family="Courier New" align="left" for="stateOther">State (Other):</label>
<input maxlength=6 align="right" type="text" name="stateOther" id="stateOther" value=""
class="text ui-corner-all" />
<br />
<label font-family="Courier New" align="left" for="zip">Zip</label>
<input align="right" maxlength=10 align="right" type="text" name="zip" id="zip" value=""
class="text ui-corner-all" />
<br />
<label font-family="Courier New" align="left" align="left" for="product">Product</label>
<input align="right" maxlength=50 type="text" name="product" id="product" value=""
class="text ui-corner-all" />
<br />
</fieldset>
</div>