function test() {
		var data = $("#form").serializeObject();
		console.log(data);	//json
		
		var headers = {"Content-Type" : "application/json" , "X-HTTP-Method-Override" : "POST"};
		$.ajax({
            type : "POST",
            url : "./goTestUrl",
            data : JSON.stringify(data),
            headers : headers,
            dataType:"json",
            success : function(res){
                alert('success');
            },
            error : function(request,status,error){
                console.log(request);
            }
        });
	}
	
	// QueryString to json
	jQuery.fn.serializeObject = function() { 
		var obj = null; 
		try { 
			if ( this[0].tagName && this[0].tagName.toUpperCase() == "FORM" ) { 
				var arr = this.serializeArray(); 
				if ( arr ) { 
					obj = {}; 
					jQuery.each(arr, function() { 
						obj[this.name] = this.value; 
					}); 
				}
			} 
		} catch(e) {
			alert(e.message);
		} finally {
		} 

		return obj; 
	};

 

위에 ajax호출을 받는 Spring 메서드는

testModel 로 받음

@PostMapping("/gogoUrl")
	public @ResponseBody Map<String, Object> gogoUrl( @RequestBody testModel testModel) {
		Map<String, Object> map = new HashMap<>();
		return map;
	}

+ Recent posts