Trabla: YAHOO.util.Connect.asyncRequest: send json string via post request
Solving:
var sURL = 'http://myapi.com/trololo';
var postBody = [{"id":"123"},{"id":"234"}];
var callback = alert('Hooray!!! Response received!');
//Clear default headers
YAHOO.util.Connect.setDefaultXhrHeader(false);
YAHOO.util.Connect.setDefaultPostHeader(false);
YAHOO.util.Connect.initHeader('Content-Type', 'application/json' ,true );
YAHOO.util.Connect.asyncRequest('POST', sURL, callback , JSON.stringify( postBody ) );
Official documents:
http://yui.github.io/yui2/docs/yui_2.5.1/docs/YAHOO.util.Connect.html
No comments:
Post a Comment