加载资源失败:http:// localhost:59913/edit.aspx/LoadLanguages服务器响应状态为404(未找到)

加载资源失败:http:// localhost:59913/edit.aspx/LoadLanguages服务器响应状态为404(未找到)

问题描述:

我还在JavaScript的页面加载方法中调用LoadLanguage,LoadLanguageSelect,LoadVideoLogLay和LoadImage JavaScript方法。以这种方式加载页面时,这些方法中的操作将在加载页面期间起作用。但是,在将javascript方法发布到asp.net cs端时出现此错误。加载资源失败:http:// localhost:59913/edit.aspx/LoadLanguages服务器响应状态为404(未找到)

我的JavaScript的页面加载方法

 function PageLoad() { 
 
      LoadLanguages(1); 
 
      LoadLanguageList(); 
 
      LoadImageGallery(); 
 
      LoadVideoGallery(); 
 
     }

而且我在Javascript

function LoadLanguageList() { 
 
      $.ajax({ 
 
       url: "Edit.aspx/LoadLanguageSelect", 
 
       dataType: "json", 
 
       data: "{}", 
 
       contentType: "application/json; charset=utf-8", 
 
       method: "POST", 
 
       success: function (result) { 
 

 
        var xmlDoc = $.parseXML(result.d); 
 
        var xml = $(xmlDoc); 
 
        var languages = xml.find("Table"); 
 
        $('#select_AddLang').empty(); 
 
        if (languages.length > 1) 
 
         $('#select_AddLang').append($("<option></option>").attr("value", 0).text("Choose a language")); 
 
        else if (languages.length == 0)//All languages has already been added. 
 
         $('#select_AddLang').css("display", "none"); 
 

 
        languages.each(function() { 
 
         var language = $(this); 
 
         $('#select_AddLang').append($("<option></option>").attr("value", language.find("Ix").text()).text(language.find("Name").text())); 
 
        }); 
 
       }, 
 
       error: function (error) { 
 
        alert(error.d); 
 
       } 
 
      }); 
 
     }

方法

function LoadImageGallery() { 
 
      $.ajax({ 
 
       url: "Edit.aspx/LoadImageGallery", 
 
       dataType: "json", 
 
       data: "{}", 
 
       contentType: "application/json; charset=utf-8", 
 
       method: "POST", 
 
       success: function (result) { 
 
        var xmlDoc = $.parseXML(result.d); 
 
        var xml = $(xmlDoc); 
 
        var pictures = xml.find("Table"); 
 
        $('#imagesList').empty(); 
 
        var x = 10; 
 
        pictures.each(function() { 
 
         var picture = $(this); 
 
         $('#imagesList').append('<li style="list-style:none;display:inline-block;">' + 
 
          '<span id="frk' + x + '" class="frk" style="width:132px;text-align:right;" onmouseover="ShowSpan(' + x + ');" onmouseout="HideSpan(' + x + ');">' + 
 
          '<button type="button" class="glyphicon glyphicon-remove picEditBtn" title="Delete" style="border:none;"' + 
 
          'onmouseover="ShowSpan(' + x + ');" onmouseout="HideSpan(' + x + ');" onclick="DeleteGalleryPhoto(\'' + picture.find("PictureUrl").text() + '\');"></button></span>' + 
 
          '<a class="example-image-link" href="/Content/Upload/Images/Gallery/' + picture.find("PictureUrl").text() + '" data-lightbox="example-set">' + 
 
          '<img style="width:132px;height:132px;" onmouseover="ShowSpan(' + x + ');" onmouseout="HideSpan(' + x + ');" src="/Content/Upload/Images/Gallery/' + 
 
          picture.find("PictureUrl").text() + '" /></a>' + '</li>'); 
 

 
         x = x + 1; 
 
        }); 
 
       }, 
 
       error: function (error) { 
 
        alert(error.d); 
 
       } 
 
      }); 
 
     }

function LoadVideoGallery() { 
 
      $.ajax({ 
 
       url: "edit.aspx/LoadVideoGallery", 
 
       dataType: "json", 
 
       data: "{}", 
 
       contentType: "application/json; charset=utf-8", 
 
       method: "POST", 
 
       success: function (result) { 
 
        var xmlDoc = $.parseXML(result.d); 
 
        var xml = $(xmlDoc); 
 
        var pictures = xml.find("Table"); 
 
        $('#videoList').empty(); 
 
        var x = 10000; 
 
        pictures.each(function() { 
 
         var picture = $(this); 
 
         var url = picture.find("VideoUrl").text(); 
 
         $('#videoList').append('<li style="list-style:none;display:inline-block;">' + 
 
          '<span id="frk' + x + '" class="frk" style="width:528px;text-align:right;" onmouseover="ShowSpan(' + x + ');" onmouseout="HideSpan(' + x + ');">' + 
 
          '<button type="button" class="glyphicon glyphicon-remove picEditBtn" title="Delete" style="border:none;"' + 
 
          'onmouseover="ShowSpan(' + x + ');" onmouseout="HideSpan(' + x + ');" onclick="DeleteGalleryVideo(\'' + url + '\');"></button></span>' + 
 
          '<video style="width:528px;height:264px;" onmouseover="ShowSpan(' + x + ');" onmouseout="HideSpan(' + x + ');" controls>' + 
 
          '<source src="/Content/Upload/Images/Gallery/' + url + '" type="video/webm">' + 
 
          'Your browser does not support the video tag.</video></li>'); 
 

 
         x = x + 1; 
 
        }); 
 
       }, 
 
       error: function (error) { 
 
        alert(error.d); 
 
       } 
 
      }); 
 
     }

[WebMethod] 
    public static string LoadLanguages() 
    { 
     string result=null; 
     Edit page = new Edit(); 
     if (LoadType == "Agency") 
     { 
      result = page.sqlOp.FillDataSet("SELECT L.Ix,L.Name FROM CONTENT C INNER JOIN [LANGUAGE] L ON L.Ix=C.LangIx WHERE [email protected] ORDER BY C.LangIx", page.sqlConnection, CommandType.Text, 5, 
       page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     if (LoadType == "Tour") 
     { 
      result = page.sqlOp.FillDataSet("SELECT L.Ix,L.Name FROM CONTENT C INNER JOIN [LANGUAGE] L ON L.Ix=C.LangIx WHERE [email protected] ORDER BY C.LangIx", page.sqlConnection, CommandType.Text, 5, 
       page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     if (LoadType == "Guide") 
     { 
      result = page.sqlOp.FillDataSet("SELECT L.Ix,L.Name FROM CONTENT C INNER JOIN [LANGUAGE] L ON L.Ix=C.LangIx WHERE [email protected] ORDER BY C.LangIx", page.sqlConnection, CommandType.Text, 5, 
       page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 

     return result; 
    } 


[WebMethod] 
    public static string LoadLanguageSelect() 
    { 
     Edit page = new Edit(); 
     string result = null; 
     if (LoadType == "Agency") 
     { 
      String strQuery = "SELECT L.Ix,L.Name FROM [LANGUAGE] L INNER JOIN CONTENT C ON C.LangIx=L.Ix WHERE [email protected]"; 
      result = page.sqlOp.FillDataSet(strQuery, page.sqlConnection, CommandType.Text, 5, 
       page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     if (LoadType == "Tour") 
     { 
      String strQuery = "SELECT L.Ix,L.Name FROM [LANGUAGE] L INNER JOIN CONTENT C ON C.LangIx=L.Ix WHERE [email protected]"; 
      result = page.sqlOp.FillDataSet(strQuery, page.sqlConnection, CommandType.Text, 5, 
       page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     if (LoadType == "Guide") 
     { 
      String strQuery = "SELECT L.Ix,L.Name FROM [LANGUAGE] L INNER JOIN CONTENT C ON C.LangIx=L.Ix WHERE [email protected]"; 
      result = page.sqlOp.FillDataSet(strQuery, page.sqlConnection, CommandType.Text, 5, 
       page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     return result; 
    } 




[WebMethod] 
    public static string LoadVideoGallery() 
    { 
     string result = null; 
     if (LoadType == "Agency") 
     { 
      Edit page = new Edit(); 
      result = page.sqlOp.FillDataSet("SELECT VideoUrl FROM GALLERY WHERE [email protected] AND VideoUrl IS NOT NULL", 
       page.sqlConnection, CommandType.Text, 5, page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     else if (LoadType == "Tour") 
     { 
      Edit page = new Edit(); 
      result = page.sqlOp.FillDataSet("SELECT VideoUrl FROM GALLERY WHERE [email protected] AND VideoUrl IS NOT NULL", 
       page.sqlConnection, CommandType.Text, 5, page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     else if (LoadType == "Guide") 
     { 
      Edit page = new Edit(); 
      result = page.sqlOp.FillDataSet("SELECT VideoUrl FROM GALLERY WHERE [email protected] AND VideoUrl IS NOT NULL", 
       page.sqlConnection, CommandType.Text, 5, page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     return result; 
    } 



     [WebMethod] 
    public static string LoadImageGallery() 
    { 
     string pictureUrl=null; 
     if (LoadType == "Agency") 
     { 
      Edit page = new Edit(); 
      pictureUrl = page.sqlOp.FillDataSet("SELECT PictureUrl FROM GALLERY WHERE [email protected] AND PictureUrl IS NOT NULL", 
       page.sqlConnection, CommandType.Text, 5, page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     else if (LoadType == "Tour") 
     { 
      Edit page = new Edit(); 
      pictureUrl = page.sqlOp.FillDataSet("SELECT PictureUrl FROM GALLERY WHERE [email protected] AND PictureUrl IS NOT NULL", 
       page.sqlConnection, CommandType.Text, 5, page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     else if (LoadType == "Guide") 
     { 
      Edit page = new Edit(); 
      pictureUrl = page.sqlOp.FillDataSet("SELECT PictureUrl FROM GALLERY WHERE [email protected] AND PictureUrl IS NOT NULL", 
       page.sqlConnection, CommandType.Text, 5, page.sqlParameters.Add("@Ix", SqlDbType.BigInt, Ix)).GetXml(); 
     } 
     return pictureUrl; 
    } 

而且我在浏览器中得到这个错误

Failed to load resource: the http://localhost:59913/edit.aspx/LoadLanguages server responded with a status of 404 (Not Found),Failed to load resource: the http://localhost:59913/edit.aspx/LoadLanguagesSelect server responded with a status of 404 (Not Found),Failed to load resource: the http://localhost:59913/edit.aspx/LoadVideoGallery server responded with a status of 404 (Not Found),Failed to load resource: the http://localhost:59913/Edit.aspx/LoadImageGallery server responded with a status of 404 (Not Found)

我看到两个问题

首先,我注意到,你的WebMethods不接受参数,但你specifting数据:“{}”在你的Ajax调用。当参数不必要时,请尝试省略此行。如果页面正在查找接受对象但未找到对象的方法,则可以返回404。看到这个答案:

How to call c# method with no parameters and access returned data?

您是否尝试过使用小提琴手正在为看你的AJAX请求?如果是这样,请确保它实际上以POST请求发送。否则服务器将搜索一个GET方法,并且不会找到一个,因此返回一个404.

我总是使用$ .ajax({type:“POST”“});而不是$ .ajax({方法:“POST”“})

+0

我做了你说的。我在数据部分添加了”{}“。我在.NET 4.5框架中使用了这些代码和方法。但是我尝试从.net 4.5框架到.net 4.0框架然后我的项目得到这个错误。 – wotmn