Max response size with ajax-request - yii2

When response size is too large Yii2 add to response message ('An internal server error'). Example: Client size:
$.ajax({
type: 'POST',
url: '/site/index',
async: false,
success: function (data) {}
});
site/index:
variant1:
echo '12345';
result: 12345
variant2:
echo '123451231242352345345234'; #10000 symbols
result: 123451231242352345345234...An internal server error.
If I duplicate this code without Yii2, this working fine.
How can I increase max response size limit in Yii2?
UPD: Problem with output_buffering value in php.ini file. In my config this value is 4096

Related

Handlebars escaping '\' character and number followed after it in AJAX request even after using {{{ expression

I am using an AJAX request and Handlebars to communicate the data transfer as shown below.
main.hbs
<script>
..
$.ajax({
type: "POST",
data: JSON.stringify({
propId: "{{staysAt}}",
propImg: "/{{propImg}}",
_csrf: "{{csrfToken}}"
}),
contentType: 'application/json',
dataType: 'json',
url: "/user/sendRequest",
success: function(result){
},
error: function(err){
//console.log(err);
}
})
..
</script>
In propImg data is being stored as
/uploads 8-11-27T10-54-19.118Zparis-graph-colored.png
Instead of
/uploads\2018-11-27T10-54-19.118Zparis-graph-colored.png
When i use main.hbs to display the Handlebar object outside the AJAX request it works perfectly
<h2>/{{propImg}}</h2>
and gives the complete image path, however inside the AJAX call I do not understand what is going wrong.
I tried using {{{propImg}}} for no escape as well however the same issue is coming.

Ajax request from file://

I am having real difficulty knowing what to do. I have been reading some sources that are inferring that you cannot make ajax calls when launching an html file from the local file system (file:// in the url).
I have a html file on my desktop (ie in the browser url file://) containing the following ajax call:
$.ajax({
type: "POST", // This for array
url: "http://www.mywebsite.com/exclude.php",
async: true,
cache: false,
crossDomain: true, // This needs to be true for other people
success: function (data) {
var json = jQuery.parseJSON(data);
// Use json in interesting ways
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// Silent error
}
});
My php file on my server is basic:
<?php
header("Access-Control-Allow-Origin: *"); // To allow cross domain
$KeyCodeStatics_BlackList = ["181K2", "4V419"];
echo json_encode($KeyCodeStatics_BlackList);
?>
Some are suggesting ajax calls are not allowed from an html file launched in the local file system (file:// in url).
The errors I am getting:
Origin file: not found in Access-Control-Allow-Origin header.
and
XMLHttpRequest: Network Error 0x80700013, Could not complete the operation due to error 80700013.
How can I overcome this? I need to make an async call to /www.mywebsite.com/exclude.php from the html file from my local file system.
Note: It is not just me that has to do it, it is every end-user that uses this html file. So this means I cannot ask them to change security settings on their browser.

Operation not supported error while PUT to Dynamic CRM Web API

I'm using the following JS to change the name of an account entity using CRM 2016's Web API:
data = JSON.parse('{"name":"<new name>"}');
data = JSON.stringify(data);;
$.ajax({
type: "PUT",
url: "https://<mySite>.dynamics.com/api/data/v8.0/accounts(<accountId>)",
data: data,
contentType: "application/json"
});
But my site returns the following error:
Message":"Operation not supported on account","ExceptionMessage":"Operation not supported on account","ExceptionType":"Microsoft.Crm.CrmHttpException"
What might be the problem?
When using PUT request to update a single property, the property name should be appended to the Uri of the entity.
Try this script:
data = JSON.parse('{"value":"<new name>"}');
data = JSON.stringify(data);;
$.ajax({
type: "PUT",
url: "https://<mySite>.dynamics.com/api/data/v8.0/accounts(<accountId>)/name",
data: data,
contentType: "application/json"
});

How to Enable ajax request caching for semi dynamic data (ie JSON)?

I have to cache json data for my phonegap applicaiton for 10 minutes how to do that?
server response is already with the expiry headers.
Cache-Control: max-age=315360000
Expires: Sun, 12 Sep 2038 20:15:20 GMT
BUT jquery ajax request is not being cached.
[a] Sometimes we need to enable and disable ajax request caching for browsers. can be done via below flag. cache: true
if set to true ajax request will start caching depending upon the content deposition header.
if set to false a unique timestamp will be appended to request so
that request is never cached.
http://www.exp.com/api/get_posts/?count=12&page=1&_=1381305201264
code:
global_xhrAbort = $.ajax({
cache: true,
type: "GET",
timeout: 30000,
async: false,
url: finalurl,
data: null,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "json",
complete: function () {
},
success: function (data) {
console.log('picked from server koimoi: success');
Page_topstoriesJson = GetJSONifNeeded(data); ;
HTMLSTORAGE_SET('landingpage', GetJSONstringfyifNeeded(data)); //will expire in ten mintues
doChangesForMainandTopStoriesSlider();
HideLoading();
}
,
error: function (errmsg) {
alert_dialog('Request failed. Please check your internet connection or Press Refresh Button.',true);
console.log('index_devicreReadyError: ' + errmsg);
}
});
Jquery AJAX cache documentation : (default: true, false for dataType 'script' and 'jsonp')
Type: Boolean
If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.
[b] Remember: Ctrl+R on chrome always loads new data from server, even if its cached. Open page in new window to see the results while testing.

couchDB: download results of list query as attachment

I have a list that produces a csv file. Querying that is simple, and if it is queryied from a link, it downloads the response as an attachment (provided the correct headers are sent).
However, I need to POST a potentially large amount of dynamically generated data (an array of keys). It's too large to just append to the url, i need to post the data as, well, data.
My usual ajax query is:
$.ajax({
type: 'POST',
dataType: 'text',
url: '/' + treatmentDatabaseString + '/_design/webview/_list/treatmentTable/treatmentTable?include_docs=true'
data: JSON.stringify({
'keys': keys // DATA THAT NEEDS TO BE POSTED
}),
error: function(status) {
alert('db error (keyed): ' + JSON.stringify(status));
},
success: function(data) {
// ..do stuff
}
});
Is there some way that I can alter the link so that it posts this data? or any other way I can make the result of this query download as an attachment?
If the incoming data is supposed to be JSON, you need to set contentType to application/json in your ajax call.