ajax 요청을 통해 가져 왔을 때 올바르게 표시되도록 머리에 링크 된 스타일 및 processing.js 스크립트를 수정하고 싶습니다. 아약스 요청에서이 코드가 필요한 위치를 볼 수 있지만 단순히 스크립트를 다시 적용하는 코드를 알려주는 방법을 모르겠습니다. 사람들이 getScript()를 사용하여이 작업을 수행하는 것을 보았습니다. 그러나이 작업을 반복 또는 재 작업한다고 말하는 것보다는 스크립트를 다시로드하는 것으로 알 수 있습니다. 모든 스크립트가 다시 초기화해야합니까? 구문 하이라이팅 .highlight() 메소드를 찾았지만 아직로드 할 프로세싱 스크립트를 얻지 못했습니다. 현재 Processing.loadSketchFromSources($('#processing'), ['mysketch.pde']);
이 작동하지 않습니다. 모든 라이브러리의 최신 버전을 사용하고 있습니다. 많은 사람들이 똑같은 문제를 갖고있는 것 같아 놀랍습니다. 아직 답을 찾을 수 없었습니다. 당신의 도움을 주셔서 감사합니다!ajax 요청 후 processing.js 스케치를 다시 초기화하십시오.
인덱스 페이지 :
$(document).ready(function() {
// put all your jQuery here.
//Check if url hash value exists (for bookmark)
$.history.init(pageload);
//highlight the selected link
$('a[href=' + document.location.hash + ']').addClass('selected');
//Search for link with REL set to ajax
$('a[rel=ajax]').live("click",function(){
//grab the full url
var hash = this.href;
//remove the # value
hash = hash.replace(/^.*#/, '');
//for back button
$.history.load(hash);
//clear the selected class and add the class class to the selected link
$('a[rel=ajax]').removeClass('selected');
$(this).addClass('selected');
//hide the content and show the progress bar
//$('#content').hide();
$('#loading').show();
//run the ajax
getPage();
//cancel the anchor tag behaviour
return false;
});
});
function pageload(hash) {
//if hash value exists, run the ajax
if (hash) getPage();
}
function getPage() {
//generate the parameter for the php script
var data = 'page=' + encodeURIComponent(document.location.hash);
$.ajax({
url: "loader.php",
type: "GET",
data: data,
cache: false,
success: function (html) {
//hide the progress bar
$('#loading').hide();
//add the content retrieved from ajax and put it in the #content div
$('#content').html(html);
//display the body with fadeIn transition
$('#content').fadeIn('fast');
//reapply styles?
//apply syntax highlighting. this works
SyntaxHighlighter.highlight();
//relaod processing sketch, currently displays nothing
Processing.loadSketchFromSources($('#processing'), ['mysketch.pde']);
}
});
}
이 아약스 -로드 된 내용 :
이<!--ajax'd content-->
<??>
<h2>code</h2>
<pre class="brush: php">
$last_modified = filemtime("header.php");
echo("last modified: ");
echo(date("m.j.y h:ia", $last_modified));
</pre>
<script type="application/processing">
</script>
<canvas data-processing-sources="mysketch.pde" id="processing">
</canvas>
</div>
</body>
</html>
<??>
이제 코드를 추가 할 수 있습니다. 대답은 절대로 나오지 않을 것입니다 ... –
두 번째로, 여전히 : Ajax 요청 이전에 실행 된 JS가 있고 DOM에 무언가를 추가하면 분명히 영향을받지 않습니다. 이전 코드. – Viruzzo
그래서 내 질문에 .js가 다시 불을 쬐는 지 어떻게 생각하세요? 나는 나 혼자서 그것을 알아낼 수 있을지도 모른다. – expiredninja