您可以使用/ echo/json/URL來模擬JSON調用。在您爲例,你必須你的JSON文件
{
"profiles": [
{ "firstName": "Jane", "lastName": "Doe", "gender": "female" },
{ "firstName": "John", "lastName": "Doe", "gender": "male" },
{ "firstName": "Akexander", "lastName": "Beth", "gender": "male" },
{ "firstName": "Sarah", "lastName": "Kelly", "gender": "female" }
{ "firstName": "Rachel", "lastName": "Haiworth", "gender": "female" }
]
}
,並把它作爲參數傳遞給POST /回聲/ JSON /請求的內容。
var JSONData = {
"profiles": [
{ "firstName": "Jane", "lastName": "Doe", "gender": "female" },
{ "firstName": "John", "lastName": "Doe", "gender": "male" },
{ "firstName": "Akexander", "lastName": "Beth", "gender": "male" },
{ "firstName": "Sarah", "lastName": "Kelly", "gender": "female" }
{ "firstName": "Rachel", "lastName": "Haiworth", "gender": "female" }
]
}
new Request.JSON({
url: '/echo/json/',
data: {
json: JSON.encode(JSONData),
delay: 3
},
onSuccess: function(response) {
// Function to onSucess
}
}).send();
見http://doc.jsfiddle.net/use/echo.html
有你閱讀本文檔:http://doc.jsfiddle.net/use/echo.html – cirtrus
爲Ajax請求,plnkr.co是很多比小提琴更友好。您可以在幾秒鐘內創建實際文件並指向這些文件 – charlietfl