Send a json to a url (it works with ajax)

Hi,
I’m searching for a method to send a json array with a user information to a url. The web has also its own model for json and it send using this code, so it seems is ajax with a “post” message + json object :

                            `jQuery(document).ready(function(){			
                            $("form#json_form").submit(function( e ){
			e.preventDefault();

			var o = {};
			var a = $(this).serializeArray();
			$.each(a, function() {
				if (o[this.name] !== undefined) {
					if (!o[this.name].push) {
						o[this.name] = [o[this.name]];
					}
					o[this.name].push(this.value || '');
				} else {
					o[this.name] = this.value || '';
				}
			});

			o = JSON.stringify( o );

			$.ajax({
				method: "post",
				url: "http://seat.cpi.mialias.net/neuroconfigurador/public/json/send",
				data: { data : o }
			}).done(function( resp ) {
				alert( resp );
			});
		});`

I need to somehow send the same json with updated info. What addon should I try?
Thanks for the help

you can just use ofURLFileLoader setting POST in the method and whatever you send in data in the body of the ofHTTPRequest

Hey Arturo!
Thanks, is there any example in of that implement ofURLFileLoader?

something like:

$.ajax({
    method: "post",
    url: "http://seat.cpi.mialias.net/neuroconfigurador/public/json/send",
    data: { data : o }
}).done(function( resp ) {
    alert( resp );
});

would translate to:

//.h
ofURLFileLoader http;

//.cpp
ofHttpRequest request;
request.method = ofHttpRequest::POST;
request.url = "http://seat.cpi.mialias.net/neuroconfigurador/public/json/send";
request.body = "{data: o}";
auto response = http.handleRequest(request);
cout << response.data.getText() << endl;

that is synchronous and the call to handleRequest will block until it gets the response but you can check how to do it asynchronously in the imageWebLoaderExample

I’m starting a new project in of0.9.3 to try the code, and request doesn’t allow me .method and .body which version should I use?

oh, ok, that might be something we added later, it should work with the nightly builds but you can also use an addon like ofxHttp

See this example in ofxHTTP