$ .ajax에 의해 서버에서 컨텐츠를 가져오고 있습니다.
<script src="jquery-1.7.1.js" type="text/javascript"></script>
<link href="Default.css" rel="stylesheet" />
<link href="all.css" rel="stylesheet" />
<script type="text/javascript">
var dataStr = "indexOfStart=" + 0;
$(document).ready(function() {
$("#idgetData").click(function() {
$.ajax({
type: "post",
url: "http://localhost:1897/Content/Services/Service1.asmx/GetArticlesDuring",
dataType: "jsonp",
data: { indexOfStart: 0, indexOfEnd: 20 },
jsonp: 'back',
success: function (result) {
var res = decodeURIComponent(result.Result);
document.getElementById("content").innerHTML = res;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
targetDiv = $("#data");
if (errorThrown || textStatus == "error" || textStatus == "parsererror" || textStatus == "notmodified") {
targetDiv.replaceWith("请求数据时发生错误!");
return;
}
if (textStatus == "timeout") {
targetDiv.replaceWith("请求数据超时!");
return;
}
},
complete: function() {
//addStyle("Default.css");
//addStyle("all.css");
document.write('<link href="Default.css" rel="stylesheet" /><link href="all.css" rel="stylesheet" />');
}
});
});
});
function addStyle(stylePath) {
var container = document.getElementsByTagName("head")[0];
var addStyle = document.createElement("link");
addStyle.rel = "stylesheet";
addStyle.type = "text/css";
addStyle.href = stylePath;
container.appendChild(addStyle);
}
문제가 내용의 스타일로드 작업을 할 수 없다, 은 누구도 날 도와 줘요 수 있습니다 그리고 그 내용은 다음은 내 코드입니다, 그들은 자신의 오웬의 스타일을 가지고, HTML 문자열인가?
네, 맞습니다. 문제는 콘텐츠 클래스에 html이 있다는 것을 알았습니다. 스타일 클래스 이름 앞에 "+"(더하기)가 있습니다. 왜냐하면 C# 코드에서 콘텐츠를 보내기 때문에 "Server.UrlEncode (string) ", 그것은"+ "문제를 일으킬 것입니다. 그리고 나는 그 해결책을 찾았습니다 : C# 코드에서 "Microsoft.JScript.GlobalObject.encodeURIComponent (string)"을 사용하여 클라이언트의 js 코드에서 html 콘텐츠를 인코딩하고 "decodeURIComponent"를 사용하여 디코딩합니다. 너무 완벽해서 이제는 괜찮아. 그리고 너무 많이 감사합니다! – francis
도움을받을 수있어서 다행입니다. – BrotherBallan