ajax 呼び出しを行う JS 関数 (「サンプル」という名前) を含む gsp ページがあります。
function sample() {
var params = { office: {id: "testId"}, population: {id: "testId2"}};
$.ajax({
url: "http://localhost:8080/officeProj/mustache/list",
cache: false,
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json",
data: JSON.stringify(params),
complete:function(json){
console.log(" reponse :"+ json);
},
success: function(officeData) {
var template = "<h1>{{data.firstName}} {{data.lastName}}</h1>";
var html = Mustache.to_html(template, data);
$('#sampleArea').html(html);
} ,
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("error :"+XMLHttpRequest.responseText);
}
})
}
ここで、この ajax 呼び出しは、次のように定義された適切な GRAILS コントローラーと適切なアクションに到達します。
def list = {
withFormat {
html { return [title: "Mustache" , data:[firstName:"Indiana", lastName:"Jones"], address:"NYC" ] }
json {
// extract the data to be rendered to the page
println("processing JSON.....")
render ([title: "Mustache" , data:[firstName:"Indiana", lastName:"Jones"], address:"NYC" ] as JSON)
}
}
}
問題は、コントロールが controller-action で withFormat->json を決して通過しないことです。そのため、期待される結果が表示されません (コントロールが gsp ページに戻ったとき、「完了」を通過しますが、エラーは記録されていません.誰かが私の ajax 呼び出しに問題を見つけることができますか?詳細な情報を提供する必要がある場合はお知らせください.事前に感謝します.