snippetjournal

– notes, snippet codes, and my journal

Ajax posting as Data Map in spring MVC

leave a comment »

post data dengan ajax sebagai data Map di java dan spring mvc

Javascript code :


	param = {
		xx1 : "xx",
		xx2 : "xx",
		xx3 : "xx",
		xx4 : "xx"
	};
		
	// post data when page loaded
	var postParamForDatatable = $.ajax({
		url : urlContext + "post/param/xxx",
		type : "POST",
		contentType : "application/json",
		data : JSON.stringify(param)
	});

	console.log("get data ");
	// callback handler that will be called on success
	postParamForDatatable.done(function(repliedData) {
		console.log("repliedData "+repliedData);
	});

	// callback handler that will be called on failure
	postParamForDatatable.fail(function(jqXHR, textStatus, errorThrown) {
		alert("The following error occured: " + textStatus, errorThrown);
	});

	// callback handler that will be called regardless if the request failed or
	// succeeded
	postParamForDatatable.always(function() {
		console.log("callback handler that will be called regardless if the request failed or succeeded");
	});

Java controller dengan spring mvc


	@RequestMapping(value = "/post/param/xxx", method = RequestMethod.POST)
	public @ResponseBody String getdataParam(@RequestBody Map<String, Object> searchParam, HttpServletRequest request, HttpServletResponse response) {
		System.out.println("================ "+searchParam);
		
		return "ok";
	}

Written by snippetjournal

January 15, 2015 at 6:57 am

Posted in Programming

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: