I want to return javascript function from asmx as string like following..
All html tags return but checkNewMsg variant 'script tag' doesnt return!
What happens really ?
Please advice
<script type="text/javascript">
function getWindow(FromUserID, UserID, PerID, UserName) {
$.ajax({
type: "POST",
url: "TestMessageService.asmx/OpenWindow",
data: "{'FromUserID': '" + FromUserID + "', 'ClickedUserID': '" + UserID + "', 'ClickedPerID': '" + PerID + "', 'ClickedUserName': '" + UserName + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var msgs = response.d;
$('#div_Panel').append(msgs).fadeIn("slow");
var elements = $('.panelContent');
for (var i = 0; i < elements.length; i++) {
elements[i].scrollTop = elements[i].scrollHeight;
}
},
failure: function (msg) {
$('#div_Panel').text(msg);
}
});
}
</script>
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public string OpenWindow(string FromUserID, string ClickedUserID, string ClickedPerID, string ClickedUserName)
{
string checkNewMsg = "<script type="text/javascript">window.setInterval(fc_" + ClickedUserName.Replace(" ", "") + ", 10000); function fc_" + ClickedUserName.Replace(" ", "") + "() { alert('" + ClickedUserName + "'); }</script>";
StringBuilder sb = new StringBuilder();
sb.Append(checkNewMsg + "<div class="ch_Box">");
sb.Append("<div class="ch_Header">");
sb.Append("<div style="float:left;margin-top: 9px;margin-left: 8px;"><img src="Images/Status.png"></div>");
sb.Append("<div id="roomUsers" class="ch_HeaderItem">" + ClickedUserName + "</div>");
sb.Append("<div onclick="closePanel(this)" style="width: 23px; height: 27px; cursor: pointer; position: absolute; margin-left: 232px;"><img style="height: 20px; margin-top: 4px;" src="Images/close.png"></div>");
sb.Append("<div id="cont_" + ClickedUserID + "" class="panelContent">" + FillMessages(roomID, FromUserID.ToInt()) + "</div>");
sb.Append("<div class="ch_Text">");
sb.Append("<input id="msg_" + FromUserID + "_" + ClickedUserID + "_" + ClickedPerID + "_" + roomID + "" type="text" class="inp" onkeypress="PushText(this)" autocomplete="off" /></div>");
sb.Append("</div></div>");
return sb.ToString();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…