When new entry added into datagrid, and if page is not refreshed but some rows deleted,
tornado receives same added data as post, along with delete method
Why is that happening? I have differnt transport methods for each:
transport: {
read: {
url: '/api/notes/',
dataType: 'json',
type: 'GET',
},
create: {
url: '/api/notes/',
dataType: 'json',
type: 'POST'
},
update: {
url: '/api/notes/',
dataType: 'json',
type: 'PUT',
},
destroy: {
url: function(row) {
return '/api/notes/' + row.id;
},
type: 'DELETE',
},
ok, doing $("#grid").data("kendoGrid").dataSource.read(); on create.complete fixed it.
Related
$.ajax({
url: '{{ route('add.orders') }}',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: JSON.stringify({
myArr : myArr
}),
cache: false,
type: 'POST',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert(data);
}
})
my controller:
public function addOrders(Request $request) {
return $request->myArr;
}
I'm getting this one:
this is myArr:
How can i reach the object? Why it seems [object Object]
Can i reach myArr[0].id
İf you help me i will be glad, thank you.
You have to use like below
for(var i=0;i<data.length;i++){
console.log(data[i].id);
console.log(data[i].food_title);
}
$.ajax({
url: "{{ route('add.orders') }}",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data:{ myData: JSON.stringify(myArr),_token:"{{ csrf_token() }}" },
cache: false,
type: 'POST',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
console.log(data);
}
});
#At Controller
public function addOrders(Request $request) {
dd($request->all());
}
I know this question has been asked with answers I have reviewed over and over. I still can not get this kendo dataSource update function to fire. It fires without the function(e) {}
update:
{
url: "/SettingsAdmin/UpdateGrid",
dataType: "json",
type: "POST",
//data: {
// result: kendo.stringify(result.data)
//},
},
That works. What doesn't work is when I try implementing the update as a function
update: function(e)
{
debugger
alert("update")
$.ajax({
url: "/SettingsAdmin/UpdateGrid",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
data: {
models: kendo.stringify(e.data.models)
},
success: function (result) {
alert(e.success(result));
},
error: function (result) {
alert(e.error(result))
e.error(result);
}
});
},
Here is the whole dataSource defined.
return new kendo.data.DataSource({
transport: {
read: {
url: url,
contentType: 'application/json; charset=utf-8',
type: "POST",
dataType: "json"
},
update:
{
url: "/SettingsAdmin/UpdateGrid",
dataType: "json",
type: "POST",
//data: {
// result: kendo.stringify(result.data)
//},
},
update: function(e)
{
debugger
alert("update")
$.ajax({
url: "/SettingsAdmin/UpdateGrid",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
data: {
models: kendo.stringify(e.data.models)
},
success: function (result) {
alert(e.success(result));
},
error: function (result) {
alert(e.error(result))
e.error(result);
}
});
},
parameterMap: function (data, operation) {
return JSON.stringify(data);
}
},
schema:
{
data: "result.data",
total: "result.total",
aggregates: "result.aggregates",
groups: "result.groups",
errors: "result.errors",
model:
{
id: "name",
//fields: {
// //id: { required: false, type: 'number', nullable: true },
// name: { editable: false, type: "string" },
// value: { editable: true, type: "string" }
//}
}
},
pageSize: 10,
batch: false,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
});
All transport actions (read, update, create, destroy) must be defined in the same way which I wasn't doing. I had defined my read action as
read: {
url: url,
contentType: 'application/json; charset=utf-8',
type: "POST",
dataType: "json"
},
And then the update with a function
update: function(e)
{ }
Can't do that. I need to define my read: as a function
I am able to read specific data from responses with ajax GET example by using data.investing.
but one of my data name is unrest and war and i am unsure how do i write it inside my javascript, as i tried data.unrest and war and it didnt work.
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type: 'GET',
url: "https://agile-bayou-24340.herokuapp.com/users/getTodayData",
contentType: 'application/json',
dataType: 'json',
responseType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'application/json',
},
success: function (data) {
console.log(data.investing[0].title);
$('#div1').html((data.investing[0].title));
},
error: function (error) {
console.log("Error");
}
});
});
});
this is my current code
You can parse Json to Array and use key's
success: function (data) {
data = $.parseJSON(data)
console.log(data['investing'][0]['title']);
$('#div1').html((data['investing'][0]['title']));
},
Have anyone got issue in ajax post request in laravel 5.4. I am unable to get request data in controller.
Ajax request is something like this:
$.ajax({
data: { 'selected_data':[2,4,5] },
type: "POST",
url: "{{ url('test') }}",
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
success: function (res) {
console.log(res)
},
});
In controller method, i am just doing
dd($request->all());
But getting empty array. can anyone help me with this issue?
Thanks!
Instead of this:
$.ajax({
data: { 'selected_data':[2,4,5] },
type: "POST",
url: "{{ url('test') }}",
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
success: function (res) {
console.log(res)
},
});
Try this:
$.ajax({
data: { selected_data:[2,4,5], _token: "{{csrf_token()}}" },
type: "POST",
url: "{{ url('test') }}",
success: function (res) {
console.log(res)
},
});
I get onloading the jqGrid a error as follow:
load error: Error: Invalid XML: {"d":[{"id":1,"name":"Medical
1","city":"Kiev","instituteTypeId":0},{"id":2,"name":"Medical
2","city":"Kherson","instituteTypeId":0}]}
however I use JSON, oleg advised me to open new threat.
The jquery code is:
mtype: 'POST',
contentType: "application/json",
url: "dataServices/objects.asmx/InvokeData",
ajaxGridOptions: {
contentType: 'application/json; charset=utf-8'
},
postData: JSON.stringify({q: "med&1"}),
loadonce: true,
dataType: 'json',
jsonReader: {
root: function (obj) {
alert(obj.d);
return obj.d;
},
page: "",
total: "",
records: function (obj) {
return obj.d.length;
},
},
gridview: true,
loadError: function (xhr, status, error) {
alert('load error: ' + error);
},
There is no dataType= xml or anything defined....
You use dataType: 'json' which is wrong. jqGrid has the option datatype and no dataType. So you should use dataType: 'json'. Unknown option dataType will be just ignored and default option dataType: 'xml' will be used.
Additionally I think you should use just jsonReader: { root: "d" }.
The demo should be close to what you need. So you should do something like
$("#list").jqGrid({
mtype: 'POST',
url: "dataServices/objects.asmx/InvokeData",
datatype: "json",
ajaxGridOptions: {
contentType: "application/json; charset=utf-8"
},
postData: JSON.stringify({q: "med&1"}),
loadonce: true,
jsonReader: { root: "d" }
...
});