Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
C#
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
C#
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 .

C#
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);
       }

JavaScript
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
 
Share this answer
 
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(...)
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. :-
C#
var jsonResult = Json(Getlocation, JsonRequestBehavior.AllowGet);
jsonResult.maxJsonLength = int.MaxValue;
return jsonResult;
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900