jQuery .ajax 방법 fiddle is here을 통해 JSON 양식을 제출하는 데 2 가지 문제가 있습니다. 현재 함수를 사용하여 양식 데이터를 가져 오면 'Uncaught TypeError : 순환 구조를 JSON으로 변환'오류가 발생하며 양식의 날짜 선택 도구에서 날짜를 제출해야한다고 생각합니다. 내가 바로 하나의 형식을 얻이 수없는 것양식을 JSON으로 변환하는 중 오류가 발생했습니다.
From json.org : "A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested."
, 나는 다음과 같은 데이터를 제출해야합니다
{
"type": "value",
"identification": {
"ssn": "value"
},
"date_of_birth": "value",
"name": {
"first": "value",
"middle": "value",
"last": "value"
},
"address": {
"street1": "value",
"street2": "value",
"city": "value",
"state": "value",
"postal_code": "value",
"country_code": "value"
}
}
과 중첩 된 부모, 자녀 및 손자 중첩을 얻을하는 방법을 잘. 여기
function ConvertFormToJSON(form) {
var array = $(form).serializeArray();
var json = {};
$.each(array, function(){
json[this.name] = this.value || '';
});
return json;
}
및 제출
$('#USForm').validate({
errorLabelContainer: "ul#msgBox",
wrapper: "li",
submitHandler: function(form) {
var form = this;
var json = ConvertFormToJSON(form);
$.ajax({
type:'POST',
url:'http://ec2-54-201-216-39.us-west-2.compute.amazonaws.com/testc/WebService.asmx?op=VerifyIdentityJson',
crossDomain:true,
data: json,
dataType : 'json'
})
.always(function(){
console.log("always:" + json);
})
.done(function (response){
console.log("done:" + json);
})
.fail(function(){
console.log("fail" + json);
});
return false;
},
rules: {
//rules
},
messages: {
//messages
});
오류가 발생하는 이유는 없습니다. –
'jQuery.validation' 라이브러리를로드하지 않은 상태에서 문제를 재현하는 데모를 생성하십시오. – undefined
죄송합니다. 바이올린 링크를 업데이트했습니다. –