Files
emails/ui/resources/views/layout/body/footer/scripts/main.blade.php
2022-11-25 20:52:59 -03:00

38 lines
1.5 KiB
PHP

<script type="text/javascript">
const Send = {
base_url: '{{$urls->api}}',
base: function({method, uri, data = null, dataType = 'json', contentType = 'application/json'}) {
const url = this.base_url + '/' + uri.replace(/^\//g, '')
const options = {
method,
url,
crossDomain: true,
headers: {
'Authorization': [
'Bearer {{$api_key}}'
]
},
dataType
}
if (method.toLowerCase() !== 'get' && data !== null) {
if (!(typeof data === 'string' || data instanceof String)) {
options['data'] = JSON.stringify(data)
}
options['contentType'] = contentType
}
return $.ajax(options)
},
get: function(uri, dataType = 'json') {
return this.base({method: 'get', uri, dataType})
},
post: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
return this.base({method: 'post', uri, data, dataType, contentType})
},
put: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
return this.base({method: 'put', uri, data, dataType, contentType})
},
delete: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
return this.base({method: 'delete', uri, data, dataType, contentType})
}
}
</script>