The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Ajax response html

3 posters

Go down

Solved Ajax response html

Post by TamDonCo 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
TamDonCo
Forumember

Posts : 427
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: Ajax response html

Post by Ch@lo Valdez 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
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

Solved Re: Ajax response html

Post by Ch@lo Valdez 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
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

Solved Re: Ajax response html

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

Thanks Ch@lo Valdez

let me try which one is better
TamDonCo
TamDonCo
Forumember

Posts : 427
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: Ajax response html

Post by TamDonCo 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
TamDonCo
Forumember

Posts : 427
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: Ajax response html

Post by Ape September 26th 2016, 3:52 am

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


Ajax response html Left1212Ajax response html Center11Ajax response html Right112
Ajax response html Ape_b110
Ajax response html Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19075
Reputation : 1988
Language : fluent in dork / mumbojumbo & English haha

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

Back to top Go down

Back to top

- Similar topics

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