2016-12-16 163 views
0

我還在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)

回答

0

我看到兩個問題

首先,我注意到,你的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

相關問題