responseText

Discutii legate de AJAX, jQuery, MooTools, Prototype, Dojo, Yahoo! UI Library,script.aculo.us, ExtJS,AngularJS, Backbone.js, Ember.js, KnockoutJS

Moderator: Moderatori

alqin
PHPRomania Supporter
Mesaje: 17
Membru din: Joi Feb 12, 2009 5:18 pm

responseText

Mesajde alqin » Vin Feb 20, 2009 4:47 am

My first post... :)

Intr-un responseText am:

Cod: Selectaţi tot

<div id="output">
<h4>Some Title</h4>
<p>Some Text</p>
<b>Some Bold Text</b>
</div>

Fara sa folosesc innerHTML cum pot sa pun contentul lui <div id="output"> in <div id=""targetDiv">?

In exemplu de mai jos ce lipseste pentru a fi functionabil?

Cod: Selectaţi tot

      function inHtml(fromId,toId) // inlocuieste InnerHTML
      {
         var fromNode=document.getElementById(fromId);
         var toNode=document.getElementById(toId);
         if (toNode.hasChildNodes())
         {
            while(toNode.childNodes.length >= 1)
               toNode.removeChild(toNode.firstChild );
         }
         for(var n=0; n<fromNode.childNodes.length; n++)
            toNode.appendChild(fromNode.childNodes[n].cloneNode(true));
      }
xhr.responseText;
// ce trebuie sa fac ca <div id="output"> sa fie gasit in linia urmatoare?
 inHtml('output','targetDiv')



Avatar utilizator
kleampa
Senior Member
Mesaje: 2774
Membru din: Dum Iul 10, 2005 2:12 pm
Localitate: Bucuresti
Contact:

Mesajde kleampa » Vin Feb 20, 2009 10:22 am

document.getElementById('targetDiv').innerHTML = responseText;

lorand1
Average Member
Mesaje: 108
Membru din: Vin Apr 25, 2008 7:44 pm
Localitate: Baia Mare

Mesajde lorand1 » Vin Feb 20, 2009 2:56 pm

exemplu functional fara sa folosesti innerHTML

Cod: Selectaţi tot

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>
      Untitled
    </title>
<script type="text/javascript">
<!--
function createDiv(){
  newdiv = document.createElement("div");
  adatr = newdiv.setAttribute("id","targetDiv");
  docbody = document.getElementsByTagName("body").item(0);
  docbody.appendChild(newdiv);
  x = document.getElementById("output");
  i=0;
  while(i<x.childNodes.length){
        a = Array();
        y = Array();
        a[i] = x.childNodes[i];
        y[i] = a[i].cloneNode(true);
        newdiv.appendChild(y[i]);
        i++;
  } 
}
// -->
</script>
  </head>
  <body>
    <div id="output">
      <h4>Some Title</h4>
      <p>Some Text</p>
      <b>Some Bold Text</b>
    </div>
   <p onclick="createDiv();">click aici</p>
  </body>
</html>


dar iti recomand sa mai studiezi xml dom cu ajutorul js
Oamenii normali nu stiu ca totul e posibil. David Rousset
Nu am vreo insusire speciala, ci sunt numai un pasionat curios. Albert Einstein

alqin
PHPRomania Supporter
Mesaje: 17
Membru din: Joi Feb 12, 2009 5:18 pm

Mesajde alqin » Sâm Feb 21, 2009 4:55 am

Thanks pentru raspusnuri.
lorand1 raspusnul tau is the best ... Un exemplu functional e mult mai usor de inteles mai ales pentru un incepator.

Intrebarea mea este:

Exista o posibilitate ca acel responseText daca are taguri html acele taguri sa fie cumva considerate noduri dom si nu text? Ma gandesc la ceva de genu headers, content/type... nu stiu... sunt nou...

Avatar utilizator
mihaitha
Senior Member
Mesaje: 2383
Membru din: Vin Mai 04, 2007 12:40 pm
Localitate: Sibiu
Contact:

Mesajde mihaitha » Sâm Feb 21, 2009 11:21 am

Se poate, daca output-ul fisierului apelat are structura unui XML, sa folosesti proprietatea .responseXML in loc de .responseText. responseXML iti va returna un obiect cu proprietatile in structura ierarhica a XML-ului returnat.

alqin
PHPRomania Supporter
Mesaje: 17
Membru din: Joi Feb 12, 2009 5:18 pm

Mesajde alqin » Mie Feb 25, 2009 1:41 am

Multumesc pentru raspunsuri. I got it... trebuie sa stiu xml dom...


Înapoi la “Librarii Javascript”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 39 vizitatori