양식의 특정 필드가 숫자가 아닌 텍스트인지 확인하려고합니다. 어디서부터 시작하겠습니까?jquery serialize하기 전에 유효성을 검사하십시오.
필드가 숫자이면 직렬화하고, 그렇지 않으면 빈 문자열을 보냅니다. 이유는 PHP가 각 변수의 데이터를 숫자가 아닌 문자열로 간주하기 때문입니다.
이 내 아약스 요청
$.ajax({
type: "POST",
url: "lib/calc.php",
data: $("#calcQuery").serialize(),
dataType: "html",
success: function(response)
{
$("#calcBox").html(response);
$("#calcBox").show();
clearForm("#calcQuery");
},
인이 내 양식
당신은 Validate plugin를 사용할 필요가<form id="calcQuery" class="ui-widget-shadow ui-corner-all" style="margin-top: 1em;">
<fieldset class="ui-corner-all" >
<table border="0" width="85%">
<tr>
<th><nobr><label for="curr_alloc">Current Space Allocation:</label></nobr></th>
<td align="right"><input type="text" size="5" name="curr_alloc" id="curr_alloc" /></td>
</tr>
<tr>
<td>
<table border="0" style="margin-left: .5em;">
<tr>
<td>
<input type="radio" name="curr_unit" value="KB" /><label>KB</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="curr_unit" value="MB" /><label>MB</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="curr_unit" value="GB" checked /><label>GB</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="curr_unit" value="TB" /><label>TB</label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<th><nobr><label for="curr_percent">Current Usage Percentage:</label></nobr></th>
<td align="right"><input type="text" size="5" name="curr_percent" id="curr_percent" /></td>
</tr>
<tr>
<th><nobr><label for="desired_percent">Desired Usage Percentage:</label></nobr></th>
<td align="right"><input type="text" size="5" name="desired_percent" id="desired_percent" /></td>
</tr>
</table>
</fieldset>
</form>
끈? –
@ SimplySeth 당신은 캐스팅/분석해야합니다. 나는 응답을 업데이트 할 것이다. –