Je rencontre des difficultés pour écrire le code HTML ci-dessous sur la page après une demande get asynchrone. Le HTML est fourni par un service de cartographie tiers, donc je ne peux pas le modifier moi-même, sauf lorsque j'obtiens la réponse après le $.get()
.document.writeln() rompt ma mise à jour partielle de jQuery. Comment puis-je résoudre ça?
J'ai posé la question suivante il y a quelques temps: Why is this HTML causing the page to go blank. La réponse était:
"document.write après que la page a rendu entièrement ... crée un nouveau document"
En tant que tel, serait-il possible pour moi de remplacer le document.writeln()
Fonctionne avec une fonction jQuery qui inclura le HTML dans le DOM? Si oui, qu'est-ce que je dois faire?
est-ce un cas de trouver et remplacer? Ou va-t-il même fonctionner? Existe-t-il un autre moyen de résoudre ce problème?
<!-- Chart by Corda Enterprise Server (PopChart, Highwire) Version 7.2.3.3177 (Jun 11, 2008) .NET Embedder 7.1.0.2116 -->
<script type="text/javascript">
var put2087644907Props;
var put1181439927Props;
var put433403842Props;
function getImageMap1325059360() {
put2087644907Props = new PopUpProperties;
put2087644907Props.width = 400;
// lots more of these properties being set
// not sure exactly, but this has something to do with providing hover-over functionality
document.writeln('<map name="imVB_2wFC_WSdl" id="imVB_2wFC_WSdl"><area shape="poly" coords="540,52,547,52,547,59,540,59,540,52" onmouseover="return showPopUp ? showPopUp(put2087644907Props, \'VB_2wFC_WSdl\', \'Schroder All Mats Idx Lnkd Bd I Acc 2.58%\', 543, 49) : false;"/> /* big long string */ onmouseover="return hidePopUp ? hidePopUp() : false;"/></map>');
}
</script>
<script type="text/javascript">
document.writeln('<script type="text/javascript" src="http://ie-sv-corda72:2001/?jsPopUp"></scr'+'ipt>');
if(document.layers) getImageMap1325059360();
</script>
<img id="VB_2wFC_WSdl" name="VB_2wFC_WSdl" width="570" height="243" style="border: 0;"
usemap="#imVB_2wFC_WSdl" src="http://ie-sv-corda72:2001/[email protected]_CPRVB_2wFC_WSdl" />
<script type="text/javascript">
if (!document.layers) getImageMap1325059360();
</script>
<noscript>
<map name="imVB_2wFC_WSdl" id="imVB_2wFC_WSdl">
<area shape="poly" coords="540,52,547,52,547,59,540,59,540,52" alt="Schroder All Mats Idx Lnkd Bd I Acc 2.58%" />
<area shape="poly" coords="497,41,504,41,504,48,497,48,497,41" alt="Schroder All Mats Idx Lnkd Bd I Acc 3.27%" />
<%--lots of these area elements which gives the chart hover-text functionality--%>
</map>
</noscript>
<!-- Corda Enterprise Server (PopChart, Highwire) Version 7.2.3.3177 (Jun 11, 2008) .NET Embedder 7.1.0.2116 by corda.com -->
Pour référence, c'est le code qui fait le get:
$.get(url, {}, function (result) {
$('#FactsheetTabs .tab_container').fadeOut(100, function() {
$('#tabs')
.append(result) // this fails in FireFox & chrome, but not IE... why?!
.fadeIn(100);
});
}, 'html');
Si je modifie la réponse au commentaire le code document.writeln()
comme suit, il fonctionne:
$.get(url, {}, function (result) {
$('#FactsheetTabs .tab_container').fadeOut(100, function() {
result = result.replace("document.writeln", "//document.writeln");
result = result.replace("document.writeln", "//document.writeln");
$('#tabs')
.append(result) // this works now...
.fadeIn(100);
});
}, 'html');
semble bon, mais je ne suis pas exactement sûr où mettre ça? – DaveDev
@DaveDev: avant que votre appel ajax devrait le faire. –
... à condition que 'document.expando = false;' n'ait pas été précédemment appelé dans IE. Peu probable, je l'admets. –