Thanks and am often using the developer tools to console out debugging info. I have now turned of csfr per below. The controller and method sit under Admin. I have removed the references to csfr and confirm it is working.
PHP Code:
public $globals = [
'before' => [
// 'honeypot',
'csrf' => ['except' =>
['Api/*', 'Admin/*'],
],
],
'after' => [
'toolbar',
// 'honeypot',
],
];
When I submit now, I get [] in the console for " console.log(data);" and under the network tab I get;
headers ok 200
request url;
https://development.example.com/admin/tasks/create
payload; [object Object]
preview: []
So I guess I am not sending the form data, right?
This is again my js;
Code:
$(function() {
$('#form-task-create').on('submit', function(e) {
//alert("Hello! I am an alert box!!");
e.preventDefault();
//OR can use var formData = new FormData(this);
var formData = $(this);
//var tokenHash=jQuery("input[name=csrf_token_mamamia]").val();
//We can add more values to form data
//formData.append("key", "value");
baseurl = 'https://development.example.com'
$.ajax({
url: 'https://development.example.com/admin/tasks/create',
type: 'post',
cache: false,
data: formData,
processData: false,
contentType: false,
dataType: 'json',
beforeSend: function (xhr) {
//xhr.setRequestHeader('X-CSRF-Token' , tokenHash);
},
success: function(data) {
console.log(data);
$("#resultDiv").html(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(formData);
//console.log(errorThrown+'---'+textStatus+'---'+jqXHR);
alert('Error at add data');
}
});
});
});