Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could define your own request type, or you could just listen for <code>request.ajax.preprocess</code> and do your <code>JSON.stringify</code> there – which is <em>after</em> the URL substitution has occurred.</p> <p>The <code>is_post</code> is presumably the same code you have now, just put in a different place. It's not a magic function :)</p> <pre><code> amplify.subscribe( "request.ajax.preprocess", function( defnSettings, settings, ajaxSettings ) { if ( is_post( defnSettings.resourceId ) ) { // This will still include the variable that matches the URL substitution: var _settings = $.extend( true, {}, defnSettings.data, settings.data, ajaxSettings.data ); ajaxSettings.data = JSON.stringify( _settings ); } }); </code></pre> <p>Your <code>make_request</code> would no longer <code>stringify</code>:</p> <pre><code>function make_request(resource, params, success_cb, error_cb) { amplify.request( resourceId: resource data: params success: success_cb error: error_cb ); } </code></pre> <p>Then your request can be run as normal:</p> <pre><code>make_request('document_update', {id: 1, title: "New Title" }, cb) </code></pre> <p><em><strong>Important:</strong> the way I wrote the preprocess call, it will not remove the <code>id</code> even though it matched the URL (Amplify would normally delete the matched key). If you want it to remove the <code>id</code> from the stringified JSON, replace the <code>_settings</code> assignment with this:</em></p> <pre><code>_settings = ajaxSettings.data; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload