請參考這個元件jQuery Form Plugin
javascript:
$(function(){
// bind to the form's submit event
$("#formAJAX").ajaxForm({
url: "http://localhost:8080/webproject/yourpage" ,
beforeSubmit: showRequest,
type: "get",
dataType: "json",
success: showResponse
});
});
//pre-submit callback
function showRequest(formData, jqForm, options) {
var queryString = $.param(formData);
alert(queryString);
return true;
}
//post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
alert(responseText);//單純的Text
}
//發現用showResposne的時候,responseText才會被直接轉換成JSON Object
function showResponse(responseText)
html page:<form id="formAJAX" > <input id="doSubmit" type="submit" name="button" value="submit" /> </form>
沒有留言:
張貼留言
留個話吧:)