백엔드에 값을 보내는 커피 스크립트에 ajax가 있습니다. 브라우저 패널에서 json 내부의 응답을 볼 수 있었지만 성공하면 모든 변수가 정의되지 않았습니다. 누군가 그것을 도울 수 있습니까?
여기 아약스 코드가 있습니다.
$.post '/articles/' + id + '/comments',
contentType: 'application/json'
data: comment_params:
commenter: commenter
body: body
success: (data, textStatus, jQxhr) ->
console.log(textStatus)
$('#comments').append JSON.stringify(data)
dataType: 'json'
모든 변수 data, textStatus, jxQhr
는 정의되지 않습니다. 이러한 변수에서이 값을 어떻게 얻을 수 있습니까?
수행하려는 작업에 대한 문서를 확인해야합니다.
이것은 게시를 수행하는 두 가지 방법이지만 메서드 서명이 다릅니다.
주석에서 말한 것처럼 여기에있는 것은 서로 다른 구문이 혼합 된 것이므로 둘 다 유효하지 않습니다.
대부분의 경우 $.ajax
서명 처럼 보이 므로 약간 변경할 수 있습니다. (내가 들여 쓰기도 수정했습니다. coffeescript와 같은 언어에서 중요하므로 질문에 코드를 게시 할 때 올바르게 시도해보세요.)
# Note i'm using string interpolation, not concatenation
$.ajax "/articles/#{id}/comments",
# add this key-val to determine the request type
method: "POST"
contentType: 'application/json'
data: comment_params:
commenter: commenter
body: body
success: (data, textStatus, jQxhr) ->
console.log(textStatus)
$('#comments').append JSON.stringify(data)
dataType: 'json'
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다