페이지의 전체 HTML 또는 본문 내용을 바꿔야합니다 (기존 내용에 더 많은 HTML을 추가하는 대신).AJAX 호출의 성공 콜백을 통해 페이지의 전체 HTML 또는 본문 내용을 어떻게 바꿀 수 있습니까?
대답이 here 인 경우 나에게 데이터를 반환하는 방법을 보여 주었지만 신체에 추가하면 꽤 일이 아닙니다. 이것은 내가 지금 가지고있는 jQuery를 수 있습니다 :
<script>
$(document).ready(function() {
$("#btnGetData").click(function() {
document.body.style.cursor = 'wait';
$.ajax({
type: 'GET',
url: '@Url.RouteUrl(routeName : "QuadrantData", routeValues : new { httpRoute = true , unit = "ABUELOS", begdate = "2016-08-20", enddate = "2016-08-27" })',
contentType: 'text/plain',
cache: false,
xhrFields: {
withCredentials: false
},
success: function (returneddata) {
$("body").remove;
$("body").append($(returneddata));
},
error: function() {
console.log('hey, boo-boo!');
}
}); // ajax
document.body.style.cursor = 'pointer';
}); // button click
}); // ready
</script>
을 ... 그래서 내가 먼저 본문에 HTML을 제거하기 위해 노력하고있어 참조하고 몸에 반환 된 데이터를 추가 할 수 있습니다.
이 REST 방법은 내가 원하는 HTML을 반환
[System.Web.Http.HttpGet]
[System.Web.Http.Route("{unit}/{begdate}/{enddate}", Name = "QuadrantData")]
public HttpResponseMessage GetQuadrantData(string unit, string begdate, string enddate)
{
_unit = unit;
_beginDate = begdate;
_endDate = enddate;
string beginningHtml = GetBeginningHTML();
string top10ItemsPurchasedHtml = GetTop10ItemsPurchasedHTML();
string pricingExceptionsHtml = GetPricingExceptionsHTML();
string forecastedSpendHtml = GetForecastedSpendHTML();
string deliveryPerformanceHtml = GetDeliveryPerformanceHTML();
string endingHtml = GetEndingHTML();
String HtmlToDisplay = string.Format("{0}{1}{2}{3}{4}{5}",
beginningHtml,
top10ItemsPurchasedHtml,
pricingExceptionsHtml,
forecastedSpendHtml,
deliveryPerformanceHtml,
endingHtml);
return new HttpResponseMessage()
{
Content = new StringContent(
HtmlToDisplay,
Encoding.UTF8,
"text/html"
)
};
}
을 ...하지만 그것을 교체하지 않고 반환 된 HTML을 추가 - 원래 몸 HTML은 그대로이며, 반환 된 HTML은 그것을 아래에 표시 페이지 하단.
이 html 대신 어떻게 바꿀 수 있습니까? 나는 replacewith와 replaceall을 시도했지만, 이것들은 나에게 도움이되지 못했다.
'.html] (http://api.jquery.com/html/) 함수를'.remove'와'.append' 대신' – bmceldowney
'$ ("body") 대신 사용할 수 있습니다. 제거한다; "무엇? –
제거 대신 remove()를 수행하십시오. –