Search

JQuery - How to use ajax request

2014-07-30 9:39 PM
Examples

Post

$.ajax("TARGET_URL",
 {
 "type"   : "post",
 "data"   : {"var1" : value1, "var2":value2},
 "success"  : reqeustSuccess,
 "complete"  : requestComplete,
 "error"  : requestFailure}
});

function reqeustSuccess(data, textStatus, jqXHR){
 // request success
}

function requestComplete(jqXHR,textStatus){
 if( textStatus == "success" ){
  // Request success
 }
 else{
  // Request failed
 }
}

function requestFailure(jqXHR, textStatus, errorThrown){
 // request failed
}

JQuery - 如何使用ajax要求

2014-07-29 10:17 PM
程式碼範例

Post

$.ajax("TARGET_URL",
 {
 "type"   : "post",
 "data"   : {"var1" : value1, "var2":value2},
 "success"  : reqeustSuccess,
 "complete"  : requestComplete,
 "error"  : requestFailure}
});

function reqeustSuccess(data, textStatus, jqXHR){
 // request success
}

function requestComplete(jqXHR,textStatus){
 if( textStatus == "success" ){
  // Request success
 }
 else{
  // Request failed
 }
}

function requestFailure(jqXHR, textStatus, errorThrown){
 // request failed
}