Grails의와 자바 스크립트와 아약스 ...오류 나는 클라이언트 측에서이 JQuery와 기능이
$('#add-car').on('click', function() {
$.ajax({
type: 'POST',
url: 'cars/',
data: {brand: 'brand', model: 'model', price: 100,
registryYear:1999},
success: function(data) { console.log(data)},
dataType: 'json'
});
});
그리고 서버 측
class UrlMappings {
static mappings = {
"/cars/$id?"(controller: "cars") {
action = [GET:"list", POST:"save", DELETE:"delete", PUT:"edit"]
}
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(view:"/index")
"500"(view:'/error')
}
}
import grails.converters.JSON
class CarsController {
def index() {
render (Car.findAll() as JSON)
}
def save() {
def json = request.JSON
def car = new Car(json)
car.save()
render (json)
}
def delete() {
def car = Car.findById(params.id)
car?.delete()
render (car as JSON)
}
def edit() {
def car = Car.findById(params.id)
bindData(car, request.JSON)
render (car.save() as JSON)
}
}
이 Grails의 코드를 수행 할 때
하지만 버튼 # add-car를 누르면 아무 것도 반환하지 않습니다 ... 무엇을 잘못하고 있습니까?
서버 측에서 어떤 활동이 있습니까 ?? Firebug 또는 이와 유사한 것을 사용하여 요청을 검사하고 클릭 할 때 일어나는 일을 볼 수 있습니까? – gotomanners