This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I am having a problem with a json result. When calling from the jquery it is returning a file to be saved instead of executing the success function. The get jquery request occurs in the document.ready function.
Any help would be appreciated.
public ActionResult Locations()
{
LocationsModel lm = new LocationsModel();
return Json(lm.getPins(), JsonRequestBehavior.AllowGet);
}
I have also tried:
public JsonResult Locations()
{
LocationsModel lm = new LocationsModel();
return Json(lm.getPins(), JsonRequestBehavior.AllowGet);
}
The jquery is as follows:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: this.href,
data: "{}",
dataType: "json",
success: function (msg) { getPins_success(msg); },
error: OnError
});
Thanks,
Chris
Edit:
Never mind it was a duh. Once I moved the json request to another action in the controller and loaded the view it all worked out. Now I am having parsing problems but that is another issue all together.
you should use getJson instead.
For you it would be:
$.getJSON(this.href, function (msg) { getPins_success(msg); });
This will let you parse the return data as json.
Related
Having tough times trying to deal with data (see markersMethod). Got undefined. All declared logs work fine. In order to clarify the problem, I
provide some code from 3 files related to the ajax call.
This question is NOT a duplicate because the previous was about making ajax call(I figured it out by myself) then it was closed. The actual question deals with handling already made ajax call in the controller side. As you see, these questions are completely different although they share some parts of code.
markers.ejs file
function onMapClick(e) {
coords = e.latlng;
marker = L.marker(coords);
marker.addTo(map);
foo(coords)
}
function foo(coord){
$.ajax({
url:'/markers',
type: 'POST',
dataType: 'json',
data: {coordinates: JSON.stringify(coord)},
success: function(data, text, jqXHR) {
alert(data);
},
error: function(req, status, error) {
alert(status, error);
}
});
}
markersControllers.js file
markersMethod: (req, res) => {
data = req.data;
console.log(req)
console.log('req received');
main.js file
router.post('/markers', markersController.markersMethod)
I'm trying to improve performance of a monico editor completion item provider (it is currently making ajax calls to get the appropriate items ... the custom language is very large and complex).
I'm wonderingf if/how returning a Thenable CompletionList might help with this.
https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.completionitemprovider.html
We initially started with a synchronous ajax call so that we are sure to have results to present, but that was causing too much blocking/interruption in typing flow. Now the ajax call is asynch but is not returning fast enough and we get a 'No suggestions' message.
I figured it out. In case anyone else is wondering how to do the same. From the provideCompletionItems function ...
return new Promise(function(resolve, reject) {
$.ajax({
url: 'someaddress.com',
dataType: 'json',
success: function(res) {
// create your keywords json here
resolve({items: keywords, isIncomplete: true});
},
error: function(xhr, error){
reject({items: [], isIncomplete: true})
},
});
});
The monaco editor will then display a nice little set of animated dots as a loading indicator while the ajax call happens.
Been looking at this for about two hours - I can't figure out why it's not working as $('#add').html(response), but works fine when I change the function to $('.add').html(respoonse).
Any help is greatly appreciated...
function addc() {
id=$('#id').val();
$.ajax ({
method: "GET",
url: 'addcal.php',
data: {"case":id},
success: function(response) {
$('#add').html(response);
}
});
}
It would help to see the HTML for the element you're trying to update. But also, the "#" symbol will search for an item by id. The "." symbol is to find an element by class.
I am having trouble figuring this simple thing out. Sorry I have tried all combinations of this and I cannot get it to work. Here is what I am trying to do
I have a javascrip function
function getSelectedSearchCriteria() {
var data = {};
data.projname = "Test Project";
return data;
}
my Ajax function is called as
$.ajax({
url: "/Position/PositionList",
type: "POST",
dataType: "json",
data:getSelectedSearchCriteria
}
my controller method is defined as
public ViewResult PositionList(string projname)
{
..
}
However the projname parameter is always a null. Any help appreciated
Thanks
Are you sure your javascript function is being invoked? The sample code you provide is missing a () after getSelectedSearchCriteria
data:getSelectedSearchCriteria
to
data:getSelectedSearchCriteria()
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have the following code:
var acOptions = {
source:function (request, response) {
$.ajax({
url: "index.php?option=com_fmw&view=keywords_api&controller=keywords_api&format=raw",
type: "GET", dataType: "json",
data: { expr: request.term},
sucess: function (data) {
response($.map(data, function (item) {
return item.value;
}))
}
})
},
minChars: 1,
dataType: 'json'
};
$( "#search_box_input" ).autocomplete(acOptions);
I get the following response from the server:
[{"value":"Greater"},{"value":"great"},{"value":"greatly"},{"value":"Greater-Axe"}]
However, the autocomplete field is not showing results, even though I can see that the ajax request got sent and that the server answered. What am I doing wrong?
sucess is spelt wrong. Try success instead.
success: function (data) {
response($.map(data, function (item) {
return item.value;
}))
}