我設法讓Ajax請求到服務器有兩個參數,並從服務器字符串獲得:Document對象的JavaScript
的JavaScript:
function getLetterOfResponsibilityNote(selectedCountryCode, selectedIntendedUseType) {
$.ajax({
type: "POST",
url: "/Admin/Applications/SelectLetterOfRespinsibilityNote",
cache: false,
data: { countryCode: selectedCountryCode, intendedUseType: selectedIntendedUseType },
success: function(response) {
if (response !== "") {
alert("1");
}
}
});
}
和MVC行動:
[HttpPost]
public string SelectLetterOfRespinsibilityNote(string countryCode, string intendedUseType)
{
var countryDetails = new List<ContryLetterOfResponsibility>
{
new ContryLetterOfResponsibility
{
CountryCode = countryCode,
IntendedUseType = intendedUseType
}
};
string xml = XmlSerializerUtil(countryDetails);
var country = _countryService.GetLetterOfResponsibilityNotesByCountryCodeList(xml).FirstOrDefault();
if (country != null)
{
return country.LetterOfResponsibilityNote;
}
return string.Empty;
}
我在javascript中獲取response
對象並驗證其值。如果它的值不是空字符串,我會收到警報消息。如果服務器通過JavaScript空字符串,我得到Document object
成功操作NOT EMPTY STRING。它是什麼?
你是什麼意思?你在做什麼來確定你認爲正在發生的事情? – Pointy
檢查您的數據是否來自沒有html佈局的服務器。你的佈局取消在哪裏? –