[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 908
  • Last Modified:

asp mvc jquery 404

Hi Experts.

I have an asp.net mvc application and since migrating to server, I am getting a 404 on an ajax call that works locally.

The erroro is:
<div class="content-container"><fieldset>
  <h2>404 - File or directory not found.</h2>
  <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>
 </fieldset></div>

I'm calling the following controller action in both cases:

and the javascript below:


anyone have any ideas?

[Authorize(Roles = "Role1,Role2")]
    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult SpecialistList(string specialistTypeId, string locationId)
    {
    {
      try
      {
        var query = _repository
          
            ..... load data.... 

        return Json(UserMapper.ToDto(query.ToList()));

      }
      catch (Exception ex)
      {
        // log any exceptions and return an error
        LogException(ex, HttpContext.Request);
        //return Json(ex.Message);
        return new JsonResult();
      }
    }

.....

In my view ( spark ) i have:

....

!{ Html.DropDownList ( "Location" , Locations ) }
!{ Html.DropDownList ( "SpecialistType" , SpecialistTypes ) }
!{ Html.DropDownList ( "SpecialistID" , new SelectList("Test", "test") ) }
....
	
$(function(){
  $("select#SpecialistType").change(function(){
		var location = $("select#Location").val();
        var data = $(this).val();
        var json = {specialistTypeId: data, locationId: location};
        
        $.ajax({
          type: "GET",
         url: "/Patient/SpecialistList",
         data: json,
         location: json,
         dataType: "json",
         error: function(xhr, status, error) {
           alert("error in routine: " + error );
         },
         success: function(res){
           var $dropdown = $("select#SpecialistID");
           $dropdown.find('option').remove().end();
           $dropdown.append('<option value="">..select specialist type</option>');
           for (var i = 0; i < res.length; i++) {
               $("select#SpecialistID").append('<option value="' + res[i].Id + '">' + res[i].StaffCode + '</option>');
             }
         },
       });
 });
 
  $("select#Location").change(function(){
		var location = $("select#Location").val();
        var data = $("select#SpecialistType").val();
        var json = {specialistTypeId: data, locationId: location};
        
        $.ajax({
          type: "GET",
         url: "/Patient/SpecialistList",
         data: json,
         location: json,
         dataType: "json",
         error: function(xhr, status, error) {
           alert("error in routine: " + error );
         },
         success: function(res){
           var $dropdown = $("select#SpecialistID");
           $dropdown.find('option').remove().end();
           $dropdown.append('<option value="">Select Specialist</option>');
           for (var i = 0; i < res.length; i++) {
               $("select#SpecialistID").append('<option value="' + res[i].Id + '">' + res[i].StaffCode + '</option>');
             }
             
         }
       });
 });
})

Open in new window

0
critto
Asked:
critto
1 Solution
 
jamesbaileCommented:
Id suspect that the URL of your ajax call is now invalid

$.ajax({
          type: "GET",
         url: "/Patient/SpecialistList",

Can you type /patient/specialistList in your browser?

Also in MVC 2.0 GET JSON requests are disabled by default - you have to use a POST given that security is important to you I'd recommend changing to using POSTs
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now