는 좀 아약스 처음 ... 코드를하고 있어요 :오류가 발생해도 콘솔 오류가 나타 납니까?
jQuery를
form_ajax_promise = $.ajax({
type : "POST",
url : '/orders/create_or_update',
dataType: 'json',
contentType: 'application/json',
data : JSON.stringify(params)
})
form_ajax_promise.then(
function(response) {
formSuccess(response)
},
function(response) {
formFailure(response)
}
)
에게 컨트롤러
def create_or_update
if @object.save
# corresponds with formSuccess
render json: {"id" => @order.id}, status: 200
else
# corresponds with formFailure
render json: {"errors"=> @order.errors.full_messages}, status: 400
end
end
을 success
경로가 잘 작동합니다. ... formFailure
그냥 간단한 함수라고 가정하고 failure
경로를 테스트에서
function formFailure(response){
console.log("successfully inside of formFailure")
}
내가 무슨 일이 일어나고 알았어 야하는 것은 console
위와 같이 해당 로그 메시지를 보여주고, 또한 나에게 오류를 보여주고 있다는 것입니다 :
Failed to load resource: the server responded with a status of 400 (Bad Request)
이 오류가 발생합니까? 나는 $.then
에 적절한 fail
을 제공 한 이후에 그렇게 느껴지지 않았습니까?
편집 혼란에 대한
죄송합니다, 이것은 다수의 경우가 아니라 렌더링/재 직접, I I는 행동을하지 설명하기 위해 시도 된 이후 그냥 게으른되는 다른 코드를 절단했다 . 내 실수. 코드는 위에서 편집됩니다.
'상태 : 400'으로 렌더링하고 있습니다. 따라서 올바른 행동입니다. – Sajan
두 가지 질문 (1) 어떤 버전의 jQuery? (2)'form_ajax_promise'가 더 처리 되었습니까? –
1) jQuery 2.2.4, 2) 더 이상 처리되지 않습니다 – james