The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Ajax response html

View previous topic View next topic Go down

Solved Ajax response html

Post by TamDonCo on September 22nd 2016, 10:10 pm

Code:


var id = '10' //<--- change the id
$.get('/u' + id , function (e) {
     
        console.log(e); //<--- all html tree
    });


since e is a html but we can not not user getelementbyid, getelementbyclass .. etc.

Is anyway we can use those functions to get the value ??


Last edited by TamDonCo on September 26th 2016, 2:26 am; edited 1 time in total

TamDonCo
Forumember

Posts : 180
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: Ajax response html

Post by Ch@lo Valdez on September 23rd 2016, 4:25 pm

$.get is from jquery library is a shorthand of XMLHttpRequest, also it's not possible use directly javascript for catch elements

https://xhr.spec.whatwg.org/


if you learn call data with XMLHttpRequest pure, it is possible use javascript pure or vanilla

you can do this:

Code:

var id = '104367';
$.get('/u' + id , function (e) {
    var document = $('#wrap', e)[0];
  b = document.innerHTML;
c= document.getElementsByClassName('panel')[0].textContent;
    console.log('panel html: '+ c);
});

Ch@lo Valdez
Forumember

Male Posts : 100
Reputation : 31
Language : spanish

Back to top Go down

Solved Re: Ajax response html

Post by Ch@lo Valdez on September 23rd 2016, 5:55 pm

ok, with javascript:

Code:

function loadDoc(url, cfunc) {
    var xhttp;
    xhttp=new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            cfunc(this);
        }
    };
    xhttp.open("GET", url, true);
    xhttp.responseType = 'document';
    xhttp.send();
}

function ajaxsetup(xhttp) {
 AjaxDocument = xhttp.responseXML;// <--- document
   
}

now called:
Code:
loadDoc('URL', ajaxsetup);

try
Code:
 loadDoc('/profile?mode=editprofile&page_profil=friendsfoes', ajaxsetup);

use this way:

Code:
AjaxDocument.getElementsByClassName('panel')[0].innerHTML;

Ch@lo Valdez
Forumember

Male Posts : 100
Reputation : 31
Language : spanish

Back to top Go down

Solved Re: Ajax response html

Post by TamDonCo on September 23rd 2016, 7:44 pm

Thanks Ch@lo Valdez

let me try which one is better

TamDonCo
Forumember

Posts : 180
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: Ajax response html

Post by TamDonCo on September 26th 2016, 2:26 am

Thanks Ch@lo Valdez again

both work fine, the first one is simpler, the second one more formal ..

TamDonCo
Forumember

Posts : 180
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: Ajax response html

Post by APE on September 26th 2016, 3:52 am

Problem solved & topic archived.
Please read our forum rules: ESF General Rules




APE
Manager
Manager

Male Posts : 8608
Reputation : 748
Language : fluent in dork / mumbojumbo & English haha
Location : STUCK IN FORUMOTIONS SERVERS HELP ME !!!!!!

http://chatworld.forumotion.co.uk/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum