mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-10 17:46:09 +03:00
Added a method to send JSON-encoded data.
This commit is contained in:
parent
ce1b40eac3
commit
705e01625e
@ -16,6 +16,11 @@
|
|||||||
<div id="header">
|
<div id="header">
|
||||||
<a href=""><h1>{{ apiName }}</h1></a>
|
<a href=""><h1>{{ apiName }}</h1></a>
|
||||||
<div id="sandbox_configuration">
|
<div id="sandbox_configuration">
|
||||||
|
content format:
|
||||||
|
<select id="content_format">
|
||||||
|
<option value="x-www-form-urlencoded">Form Data</option>
|
||||||
|
<option value="json">JSON</option>
|
||||||
|
</select>
|
||||||
request format:
|
request format:
|
||||||
<select id="request_format">
|
<select id="request_format">
|
||||||
<option value="json"{{ defaultRequestFormat == 'json' ? ' selected' : '' }}>JSON</option>
|
<option value="json"{{ defaultRequestFormat == 'json' ? ' selected' : '' }}>JSON</option>
|
||||||
@ -161,6 +166,9 @@
|
|||||||
headers['Accept'] = 'application/' + requestFormat;
|
headers['Accept'] = 'application/' + requestFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set content format
|
||||||
|
var contentFormat = $('#content_format').val();
|
||||||
|
|
||||||
// retrieve all the parameters to send
|
// retrieve all the parameters to send
|
||||||
$('.parameters .tuple', $(this)).each(function() {
|
$('.parameters .tuple', $(this)).each(function() {
|
||||||
var key, value;
|
var key, value;
|
||||||
@ -183,6 +191,10 @@
|
|||||||
if (value) {
|
if (value) {
|
||||||
headers[key] = value;
|
headers[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!('Content-type' in headers)) {
|
||||||
|
headers['Content-type'] = 'application/'+contentFormat;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// fix parameters in URL
|
// fix parameters in URL
|
||||||
@ -212,11 +224,20 @@
|
|||||||
endpoint = $('#api_endpoint').val();
|
endpoint = $('#api_endpoint').val();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare final parameters
|
||||||
|
var body = params;
|
||||||
|
if(contentFormat == 'json') {
|
||||||
|
body = JSON.stringify(body);
|
||||||
|
}
|
||||||
|
var data = content.length ? content : body;
|
||||||
|
|
||||||
|
console.log(contentFormat); console.log(data);
|
||||||
|
|
||||||
// and trigger the API call
|
// and trigger the API call
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: endpoint + url,
|
url: endpoint + url,
|
||||||
type: method,
|
type: method,
|
||||||
data: content.length ? content : params,
|
data: data,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
crossDomain: true,
|
crossDomain: true,
|
||||||
beforeSend: function (xhr) {
|
beforeSend: function (xhr) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user