2014-02-10 56 views
0

我使用AJAX來填充一些級聯組合框中顯示的下一圖像:AJAX響應是原始的HTML

enter image description here

當一個選項是在組合框中選擇,它應該填充「MUNICIPIO」組合框,做這樣的事情,我調用使用AJAX稱爲CargarCombos(INT intAccion,串strCodigo)的方法,此方法接收下一個信息:

enter image description here

但問題在於接收來自AJAX方法的響應時,似乎這不是調用方法提到它只是迴應說,該頁面包含相同的HTML源代碼之前,和最糟糕的是,已經在這裏看到:

enter image description here

如果你們可以幫助我,我會非常感激。謝謝。

編輯:

繼建議我加入了AJAX命令和WEBMETHOD:

AJAX:

$.ajax({ 
      type: "POST", 
      url: pageUrl + '/CargarCombos', 
      data: '{intAccion: ' + $Accion + ', strCodigo: ' + JSON.stringify($ComboBox.val()) + ' }', 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function(response) { 
       PopularControl(response.d, $control); 
      }, 
      failure: function(response) { 
       alert(response.d); 
      } 
     }); 

WEBMETHOD:

[WebMethod()] 
public static ArrayList CargarCombos(int intAccion, string strCodigo) 
{ 
    ArrayList list = new ArrayList(); 

    ////LLamo a las variables necesarias. 
    BLL.cDirecciones DireccionesDAL = new BLL.cDirecciones(); 
    Util.cFuncion oUtil = new Util.cFuncion(); 

    DataSet oDataCombos = new DataSet(); 

    oDataCombos = DireccionesDAL.CargarCombos(intAccion, strCodigo); 
    if (oDataCombos.Tables[0].Rows.Count > 0) 
    { 
     foreach (DataRow row in oDataCombos.Tables[0].Rows) 
     { 
      list.Add(new ListItem(row.ItemArray[1].ToString(), row.ItemArray[0].ToString())); 
     } 
    } 
    return list; 
} 
+0

任何機會,你可以發佈實際相關的代碼和任何錯誤? – admdrew

+0

對不起,但它沒有顯示任何不同標籤上的螢火蟲的任何類型的錯誤,抱歉沒有給你更多的信息,但這是我無法解決它的同樣的原因。 –

+0

你是通過JQuery調用WebMethod嗎? –

回答

0

從截圖,看起來你正在使用WebForms。如果是這種情況,您將發佈到實例還是靜態的方法?因爲如果它不是靜態的,或者該方法未用WebMethod屬性標記,則會發生這種情況。這是因爲您的ajax請求僅被視爲正常的完整回發。

e.g它應該看起來像

[WebMethod] 
//assuming MyModel is the name of your model class to send back to the client. 
public static MyModel CargarCombos(int intAccion, string strCodigo) 
{ 
    //whatever it is you do here 
} 
+0

嗨和感謝您的快速響應,是的它是靜態的,它有[WebMethod]標籤,ajax方法工作之前,但現在它不會無所事事。謝謝。 –

+0

好的。所以大概有些事情已經改變了。你能否更新問題以顯示代碼隱藏方法和客戶端調用,我相信我們可以弄明白。 –

0

如果你調用通過JQuery將WebMethod,請確保您的內容類型設置爲JSON例如

$.ajax({ 
     type: "POST", 
     url: "Pendientes.aspx/CargarCombos", 
     data: "{intAccion:1, strCodigo:'BAR'}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function(msg) { 
     alert(msg); 
     } 
}); 
+0

嗨,感謝您的迴應,這幾乎就像我的方法,唯一的區別是,我不得不使用組合框傳遞的字符串值的JSON.stringify函數,謝謝 –