Error in clearGridData function - jqgrid

In version 4.8.0 free Grid
When call updatedate() I receive the next error:
TypeError: p is undefined
and the problem is at line
jQuery("#100").jqGrid('clearGridData',true);
function updatedate(){
dela=$("#listdela").val();
panala=$("#listpanala").val();
jQuery("#100").jqGrid('clearGridData',true);
$.ajax({
type: "POST",
dataType: "json",
url: "<?php echo JS_MODUL_PATH?>s_100.php",
data: "q=6&dela="+dela+"&panala="+panala,
success: function (json) {
jQuery("#100").jqGrid('setGridParam',{datatype:'json',loadui:'enable',url:"s_100.php?q=1",page:1}).trigger("reloadGrid");
setTimeout(function() { eval(json.mesaj); },timpout+800);
},
error: function (data) {
eroare(true,eroareatn,eroaremsg); return false;
}
}); // ajax
}// function updatedate

Related

.NET 6 (Core) MVC application - problem with ajax call

.NET 6 (Core) MVC application. In view I have:
$("#mybtn").click(function () {
$.ajax({
type: "POST",
url: "/MyController/GetCustomer",
data: JSON.stringify({ 'id': 5 }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response, textStatus, xhr) {
alert(response);
},
error: function (xhr, textStatus, errorThrown) {
alert(textStatus);
}
});
});
and in controller:
[HttpPost]
public JsonResult GetCustomer(int? id) {
if (id == null) {
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(new { msg = "Error in the request." });
}
var customer = _db.Customers.Find(id);
return Json(customer);
}
It gets to the action method in controller, but the id is always null...
What am I doing wrong?
It gets to the action method in controller, but the id is always
null... What am I doing wrong?
To begin with, you don't need to use JSON.stringify({ 'id': 5 }) as { 'id': 5 } already in json format. In addition, contentType: "application/json; charset=utf-8", is uncessary as well, Instead, you can do as following:
Correct Format:
$("#mybtn").click(function () {
$.ajax({
url: "/MyController/GetCustomer",
type: "POST",
data: { 'id': 5 },
dataType: "json",
success: function (response, textStatus, xhr) {
alert(response);
},
error: function (xhr, textStatus, errorThrown) {
alert(textStatus);
}
});
});
Note: You are getting null in your controller because of using contentType: "application/json; charset=utf-8", and additional, Json parsing here JSON.stringify() these are only valid when you are sending parameter as object fashion. Just get rid of those two part, you are done.
Output:

How to invoke another function using a parameter fetched JSON result of API call from AJAX

I Have to get ParentId from this function using JSON result and then invoke another function given below after this function:
public fetchLibraryDatafromSharePointList(clientID:string) {
debugger;
const reactHandler = this;
jquery.ajax({
url: `${this.props.siteurl}/_api/web/lists/getbytitle('MSAs')/items?$filter=ClientID eq '${clientID}'&$orderby=Modified desc`,
type: "GET",
headers:{'Accept': 'application/json; odata=verbose;'},
success: function(resultData2) {
reactHandler.setState({
items: resultData2.d.results
});
},
error : function(jqXHR, textStatus, errorThrown) {
}
});
}
Below is the function which has to be invoked on the success of above API and the parameter is coming in the JSON result of the previous call made:-
SetState is done by reactHandler variable
public fetchDatafromSharePointList(ParentID) {
debugger;
const reactHandler = this;
jquery.ajax({
url:`${this.props.siteurl}/_api/web/lists/getbytitle('MSASummaries')/items?
$filter=Parent eq ${ParentID}$top=1&$orderby=Modified desc`,
type: "GET",
headers:{'Accept': 'application/json; odata=verbose;'},
success: function(resultData) {
/*resultData.d.results;*/
reactHandler.setState({
items: resultData.d.results
});
},
error : function(jqXHR, textStatus, errorThrown) {
}
});
}
You can invoke another function in the success response of fetchLibraryDatafromSharePointList(clientID:string) after updating state. i.e:
reactHandler.setState({
items: resultData2.d.results
}, ()=>{
fetchDatafromSharePointList(your_parent_id_goes_here);
});

Cant access spotify object

i want to display the albums of an artist that i passed from my api controller
the request is here.
I can access the info object, but when i access the albums object it returns undefined
<script>
$(function () {
$('table tr').click(function () {
var id = this.id;
$.ajax({
type: "GET",
url: '/api/author/GetName/' + id,
contentType: "text/plain charset-utf-8",
data: id,
dataType: "json",
success: function (data) {
getDetails(data.name);
}
});
}
);
});//End ready
function getDetails(art) {
$.ajax({
type: "GET",
url: 'http://ws.spotify.com/search/1/track.json?q='+ art ,
dataType: 'json',
success: function (data) {
$('#summaryDisplay').empty();
$('#summaryDisplay').append((JSON.stringify(data.albums)) + '<br/>');
alert(JSON.stringify(data.info));
},
error: function (data) {
$('#summaryDisplay').html('<h3>Error in retrieval</h3>');
}
});
}
You are accessing the wrong URL in your code. Use album instead of track.
{
// [...]
url: 'http://ws.spotify.com/search/1/album.json?q='+ art,
// [...]
}

jquery.ajax: additional argument to callback

how can I make mydata available in the success function below
function addWordAddress(mydata) {
var url = 'http://site/';
$.ajax({
url: url,
jsonpCallback: callbackName,
jsonp: false,
cache: true,
dataType: "jsonp",
success: function (json) {
console.log(json);
console.log(mydata);
},
error: function () {
console.log("error");
}
});
}

Simple jQuery / Ajax error

I have this code:
var custID = 1;
$.ajax({
url: 'php/viewCustomer.php',
type: 'GET',
data: '{custID: ' + custID + '}',
dataType: 'json',
cache: false,
beforeSend: function () {
$('#display').append('<div id="loader"> Lodaing ... </div>');
},
complete: function () {
$('#loader').remove();
},
success: function (data) {
//do something
},
error: function () {
alert('could not process');
}
});
there is an error and alerts the error message could not process, so I tried to debug it like this:
var custID = 1;
$.ajax({
url: 'php/viewCustomer.php',
type: 'GET',
data: '{custID: ' + custID + '}',
dataType: 'json',
cache: false,
beforeSend: function () {
$('#display').append('<div id="loader"> Lodaing ... </div>');
},
complete: function () {
$('#loader').remove();
},
success: function (data) {
//do something
},
error: function (jqXHR) {
alert('Error: ' + jqXHR.status + jqXHR.statusText);
}
});
which outputs:
200 OK
so if it is ok, why on earth is it executing the error: function. Confused, please help.
Your data string is incorrectly formatted, if you are intending it to be a JSON object. There was a previous question about this: Jquery passing data to ajax function
Instead, try:
data: JSON.stringify({custID: custID}),
The format is (key):(variable). My previous answer have placed quotes around the variable, which is not necessary.

Resources