Click here to Skip to main content
14,328,738 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
This is probably something simple. The following JQuery call is executing and calling the controller. The controller is executing correctly. I used the sample data that's commented out to verify that the templates were working also.

However, the (var response = data.location;) function is not executing in the browser. Any thoughts or other ways I can debug this?
function getLocations()
{    
    $.getJSON("/MapSearch/SearchLocationJson", function (data)
    {
        alert('show');       
        var response = data.location;       
        for (var i = response.length - 1; i >= 0; i--)
        {
        keywords.push(response[i]["StrLocation"]);
        kLat.push(response[i]["StrLat"]);
        kLng.push(response[i]["StrLng"]);
      }
      $("#suburbField").show();
      $("#loadingLabel").hide();
    });
}

SearchLocationJson Action execute well but alert('show') is not executing. i googled but not find the solution. Please help.
my action code is
public JsonResult SearchLocationJson()
       {
           var Getlocation = from r in odbe.ODB_LLg_Master
                             orderby r.Pcode descending
                            // select r;
                           select new
                           {
                               StrLocation = (r.A + "," + r.B+ "," + "VIC"),
                               StrL = r.L1,
                               StrL1 = r.L2
                           };
           return Json(Getlocation, JsonRequestBehavior.AllowGet);
       }


Thanks!
Posted
Updated 2-Nov-15 0:26am
v5
Comments
Gyaneswar kumar 2-Nov-15 5:10am
   
Add method attribute into that method to get Json fomrat as return type.
ErBhati 2-Nov-15 5:25am
   
Sorry,I didn't understand your answer .
Rate this:
Please Sign up or sign in to vote.

Solution 1

public JsonResult SearchLocationJson()
       {
           var location = (from r in odbe.ODB_LLg_Master
                             orderby r.Pcode descending
                            // select r;
                           select new
                           {
                               StrLocation = (r.A + "," + r.B+ "," + "VIC"),
                               StrL = r.L1,
                               StrL1 = r.L2
                           }).ToList();
           return Json(location, JsonRequestBehavior.AllowGet);
       }

function getLocations()
{    
    $.getJSON("/MapSearch/SearchLocationJson", function (data)
    {
        alert('show');             
        for (var i = data.length - 1; i >= 0; i--)
        {
        keywords.push(data[i].StrLocation);
        kLat.push(data[i].StrLat);
        kLng.push(data[i].StrLng);
      }
      $("#suburbField").show();
      $("#loadingLabel").hide();
    });
}


You don't have to return the SelectList, as it used for Dropdown items. Rather simply return the list as json and use it.
Try the above and let me know if it works.

-KR
   
v3
Comments
ErBhati 2-Nov-15 4:34am
   
dear Rohit,
Thanks for reply but this code not working also...
Krunal Rohit 2-Nov-15 4:35am
   
I've updated the code.
What's the error ?

-KR
ErBhati 2-Nov-15 4:41am
   
yes you posted after updation in my code but alert('show'); still not showing when i execute.
there is no error shows.
Krunal Rohit 2-Nov-15 4:45am
   
try with @Url.Action("SearchLocationJson", "WorkOrder") in $.getJSON(...)
and are you calling function getLocations() anywhere in your code ?

-KR
ErBhati 2-Nov-15 5:01am
   
'@Url.Action("SearchLocationJson","MapSearch")' not working in $.getJSON(...)
ErBhati 2-Nov-15 4:48am
   
I am try this also.
here is code
$.ajax({
url: '@Url.Action("SearchLocationJson","MapSearch")',
contentType: "application/json; charset=utf-8",
async: false,
dataType: 'json',
success: function (data)
//$.getJSON("/MapSearch/SearchLocationJson", {}, function (data)
{
alert('show');

var response = data;
for (var i = response.length - 1; i >= 0; i--) {
keywords.push(response[i]["StrLocation"]);
kLat.push(response[i]["StrLat"]);
kLng.push(response[i]["StrLng"]);
}
$("#suburbField").show();
$("#loadingLabel").hide();
}
});
Krunal Rohit 2-Nov-15 4:51am
   
set async: true.
And you sure, put a breakpoint to the action method. See if the control reaches there or not.

-KR
ErBhati 2-Nov-15 4:55am
   
yes i put a breakdown in my action. control reaches there.
Krunal Rohit 2-Nov-15 5:01am
   
And set the debugger; before your alert and check if data is coming from the server.

-KR
ErBhati 2-Nov-15 5:00am
   
But '@Url.Action("SearchLocationJson","MapSearch")' not working
Krunal Rohit 2-Nov-15 5:06am
   
Please debug your code properly, use F11.

-KR
Rate this:
Please Sign up or sign in to vote.

Solution 2

Thanks for suggestion and your support. now i found the problem. The problem is MaxJsonLength:(The default value for this is 2097152 characters, that is equal to 4 MB of Unicode string data.). I have billions of record in my table . so there is MaxLength Problem. If i select few thousand records than its work properly.



And i solve this problem by using this code. :-
var jsonResult = Json(Getlocation, JsonRequestBehavior.AllowGet);
jsonResult.maxJsonLength = int.MaxValue;
return jsonResult;
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100