probleme avec xmlhttprequest

Eléphant du PHP | 187 Messages

03 déc. 2008, 21:25

Bonsoir,
j'ai un probleme avec le code suivant :

Code : Tout sélectionner

addLoadEvent( 93 function() 94 { 95 var element = document.getElementById('modify_topic_select_submit'); 96 element.type = 'button'; 97 element.onclick = function() { 98 element = this; 99 this.disabled = 'disabled'; 100 document.getElementById('modify_topic_select').disabled = 'disabled'; 101 this.value = 'Veuillez patienter...'; 102 var xhr = new XMLHttpRequest(); 103 xhr.onreadystatechange = function() { 104 if(xhr.readyState == 4) 105 { 106 if(xhr.status == 200) 107 { 108 document.getElementById('modify_topic_order').disabled='disabled'; 109 element.parentNode.removeChild(element); 110 fieldsetFieldsSwitchDisplay('modify_topic'); 111 112 var topic = xhr.responseXML.getElementsByTagName('topic'); 113 topic = topic[0]; 114 115 document.getElementById('modify_topic_title').value = topic.getElementsByTagName('title')[0].firstChild.data; 116 document.getElementById('modify_topic_contents').value = topic.getElementsByTagName('contents')[0].firstChild.data; 117 118 var topicImageArea = document.createElement('p'); 119 var topicImage = document.createElement('img'); 120 topicImage.src = '../../encyclopedie/images/topics/' + topic.getElementsByTagName('id')[0].firstChild.data + '.gif'; 121 topicImage.alt = ''; 122 topicImageArea.appendChild(topicImage); 123 document.getElementById('modify_topic_fields').insertBefore(topicImageArea, document.getElementById('modify_topic_order').parentNode) 124 125 selectOrder = document.getElementById('modify_topic_order'); 126 selectOrder.removeChild(selectOrder.firstChild.nextSibling); 127 128 var xhrorder = new XMLHttpRequest(); 129 xhrorder.onreadystatechange = function() 130 { 131 if(xhrorder.readyState == 4) 132 { 133 if(xhrorder.status == 200) 134 { 135 selectOrder = document.getElementById('modify_topic_order'); 136 selectOrder.removeChild(selectOrder.firstChild.nextSibling); 137 138 var topics = xhrorder.responseXML.getElementsByTagName('topic'); 139 140 newOption = document.createElement('option'); 141 newOption.value = '1'; 142 selectOrder.appendChild(newOption.appendChild(document.createTextNode('Au début'))); 143 144 for(var i = 0; line = topics[i]; i++) 145 { 146 newOption = document.createElement('option'); 147 newOption.value = line.lastChild.firstChild.data + 1; 148 optionText = document.createTextNode(line.firstChild.firstChild.data); 149 newOption.appendChild(optionText); 150 selectOrder.appendChild(newOption); 151 } 152 selectOrder.removeAttribute('disabled'); 153 } 154 } 155 }; 156 xhrorder.open = ('GET', 'includes/javascript/ajax.xml?action=1&cat_id=4' + topic.getElementsByTagName('cat_id')[0].firstChild.data, true); 157 xhrorder.send(null); 158 } 159 } 160 }; 161 xhr.open('GET', 'includes/javascript/ajax.xml?action=2&topic_id=' + document.getElementById('modify_topic_select').value, true); 162 xhr.send(null); 163 } 164 } 165);
L'objet xhrorder produit une exception :
[Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: anonymous :: line 157" data: no]

J'ai essayé de changer pas mal de chose dans le code mais rien y fait...
si vous avez une idée,
merci,
netsupra

Modérateur PHPfrance
Modérateur PHPfrance | 2575 Messages

19 déc. 2008, 10:33

Tu as une erreur ici:

Code : Tout sélectionner

xhrorder.open = ('GET', 'includes/javascript/ajax.xml?action=1&cat_id=4' + topic.getElementsByTagName('cat_id')[0].firstChild.data, true);
Il faut enlever le "=" après ".open"

Correction:

Code : Tout sélectionner

xhrorder.open ('GET', 'includes/javascript/ajax.xml?action=1&cat_id=4' + topic.getElementsByTagName('cat_id')[0].firstChild.data, true);
L'erreur est déclenchée par "xhrorder.send(null);" car le "xhrorder.open" ne se fait pas. En effet, XHR ne peut pas envoyer la requête Ajax tantque l'url (chemin vers le serveur appelé) n'est pas ouverte.
--------//////----//---//----//////
-------//---//----//---//----//---//
------//////----//////-----//////
-----||--------||--||---||
Prendre le recul n'est pas une perte de temps.


ps: Affrontez moi dans l'arène

Eléphant du PHP | 187 Messages

19 déc. 2008, 12:48

Merci ;)

[Note : ce message a été posté de manière anonyme avant d'être réattribué à son auteur]