星期日, 5月 15, 2011

[JQuery Plugin] AJAX Form using Jquery

使用jquery達到ajax form submit的需求。
請參考這個元件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>

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails