Created
December 29, 2011 06:53
-
-
Save allen501pc/1532458 to your computer and use it in GitHub Desktop.
在MVC 3上包JSON物件,送給Controller的方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
type: "POST", /* 選擇傳輸方式 */ | |
url: "/person/create", /*選擇要處理的controller/action */ | |
dataType: "json", /*選擇資料類型,以本篇文章,資料類型為json */ | |
contentType: "application/json; charset=utf-8", /* 選擇傳輸的encoding以及媒體類型 */ | |
data: jsonData, /* data欄位填入json包好的資料就行了!以這個為例,jsonData是該篇文章的一個物件 */ | |
success: function (result){ /* 成功了要做什麼動作? */ | |
console.log(result); //log to the console to see whether it worked | |
}, | |
error: function (error){ /* 失敗了要做什麼動作? */ | |
alert("There was an error posting the data to the server: " + error.responseText); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment