Bad Server Response
Collapse
X
-
Not really understand why you add Post or change NameOfEntity .. but why you change what I have posted ?
I have send my working sample... espoCRM work with JSON..
PHP Code:<?php namespace Espo\Custom\Controllers; class NameOfYourEntity extends \Espo\Core\Templates\Controllers\BasePlus { public function actionGenerateReport($params, $data, $request) { if (empty($data->id)) { throw new BadRequest(); } console.log($data->id); return $data; } }
Leave a comment:
-
Hi
Yes, it is a button in record/detail.js
I replaced the ajax call so that it is the same as the what you have (except YOURENTITY has been replaced)
In custom/espo/custom/controllers/test.php, I have:
Code:<?php namespace Espo\Custom\Controllers; class test extends \Espo\Core\Templates\Controllers\BasePlus { public function postActionGenerateReport($params, $data) { if (empty($data->id)) { throw new BadRequest(); } return $data->id; } }
Is there anything else I should double check for errors?Leave a comment:
-
Nice,
put a file in :
Ajax Call so : I think you have put a a button : then this on your detail.js
$.ajax({
url: 'YOURENTITY/action/GenerateReport',
type: 'POST',
data: JSON.stringify({
id: this.model.id
}),
success: function (data) {
if (data){
Espo.Ui.notify("Done", 'success', 1000);
}else{
Espo.Ui.notify("Error", 'error', 1000);
}
}
});
in : custom/espo/custom/controllers/YOUR_ENTITY.php
<?php
namespace Espo\Custom\Controllers;
class YOUR_ENTITY extends \Espo\Core\Templates\Controllers\TYPE_OF_ENTITY like Person.. like .. ?
{
public function actionGenerateReport($params, $data, $request)
{
HERE FIND YOUR $params/ data/ request ..
$data->id =>> id (see up id: this.model.id )
}
}
Leave a comment:
-
Hello,
I put it the PHP code in /api/v1/custom because the url path is /espo/api/v1/ + whatever is in the url
What is the path to Contact/action/test?
Here is the full code JS code for the action in /espo/client/custom/src/views/test/record
Code:actionGenerateReport: function (data) { var parentid = data.id; if (!parentid) { return; } var model = this.collection.get(parentid); if (!model) { return; } //Find attachments and append the links to an array var attachments = this.$el.find('[data-id=' + parentid + ']').find('[data-name=capaAttachments]'); var links = []; $(attachments).children().each(function() { links.push($(this).find('a').attr('href')); }); $.each(links, function(index, value){ var path = window.location.hostname + '/espo' + value; //Sends ids to php to write into a file var id = value.substring(value.indexOf('id=')+3, value.length-1); $.ajax({ type: "POST", url: "custom/idList.php", data: {"str": id}, success: function(data){ if(data){ console.log("success"); }else{ console.log("fail"); } } }); });
Code:<?php if(isset($_POST["str"])){ $id = $_POST["str"]; file_put_contents('id.txt', $id); }else{ echo "fail"; } exec('script.bat'); ?>
Leave a comment:
-
Hi,
first give full code and the path.
Why /custom ? why Api ?
Here sample :
$.ajax({
url: 'Contact/action/test',
type: 'POST',
data: JSON.stringify({
id: this.model.id
}),
success: function (data) {
if (data){
Espo.Ui.notify("Done", 'success', 1000);
}else{
Espo.Ui.notify("Error", 'error', 1000);
}
}
});
And then put controller and get ID
Regards. (I am not a specialist but it's work)Leave a comment:
-
Bad Server Response
Hi, I am trying to execute an ajax call, but I keep getting "Bad server response". I am trying to get a list of ID's and put them into a separate text file
Here is my ajax call:
Code:var id = value.substring(value.indexOf('id=')+3, value.length-1); $.ajax({ type: "POST", url: "/custom/idList.php", data: {"str": id}, success: function(){ console.log("success"); } });
Here is my PHP file under \api\v1\custom
Code:if(isset($_POST["str"])){ $id = $_POST["str"]; file_put_contents('path.txt', $id); }
Tags: None
Leave a comment: