내가 jQuery를 사용하고 있는데 콘솔 나 반환개체를 문자열로 변환하는 방법은 무엇입니까?
Data Loaded: [object Object]
을 jQuery를 :
$(document).ready(function(){
//Button click event
$("#ajaxForm").submit(function(e){
// disable the form submit
e.preventDefault();
});
/* get some values from elements on the page: */
var $form = $(this),
term = $form.find('input[name="id"]').val(),
url = $form.attr('update');
/* Send the data using ajax */
var posting =
$.ajax({
url: url
});
$.post(url, { id: term }).done(function(data) {
console.log("Data Loaded: " + data);
$("#result").empty().append(data);
});
});
나는 "문자열"에서 'JSON'의 결과를 변환 할 수있는 방법에 대해 설명합니다. 감사.
왜 그렇게하고 싶습니까? jQuery는 JSON => 객체를 변환하기위한 방법을 없앴습니다. 왜냐하면 그것이 거의 모든 시간에 필요하기 때문입니다. 그러나 어떤 경우 든 문자열을 원한다면'$ .post'의'dataType : 'text'옵션을 사용하면이를 막을 수 있습니다. – Jon
로깅 목적으로 사용한다고 생각합니다. JSON이 단순히 Object라는 문구가 아니라 JSON의 내용을 원합니다. – Flater
맞습니다. 로깅 용입니다. –