tuchawat tuchawat - 1 month ago 7
Javascript Question

Can I put jquery code in a bunch of pure javascript code?

Is it possible to insert my jquery code into a bunch of javascript code

I want to put the

$ajax
jquery code into
function getInfo()
but seem not work.I try to wrap all js code with
document.ready
but not work too.

window.fbAsyncInit = function() {
FB.init({
appId: '201637766943985',
cookie: true,
xfbml: true,
version: 'v2.8'
});
FB.AppEvents.logPageView();
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'We are connected.';
document.getElementById('fb_login').style.visibility = 'hidden';
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'We are not logged in.';
} else {
document.getElementById('status').innerHTML = 'You are not logged into Facebook';
}
});
};

(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function fb_login() {
FB.login(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'We are connected.';
document.getElementById('fb_login').style.visibility = 'hidden';
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'We are not logged in.';
} else {
document.getElementById('status').innerHTML = 'You are not logged into Facebook';
}
}, {
scope: 'email'
});
}
function getInfo() {
FB.api('/me', 'GET', {
fields: 'first_name,last_name,name,id,email'
}, function(response) {
////////call jquery AJAX here/////////////////////
});
}

function fb_logout() {
FB.logout(function() {
document.location.reload();
});
}

Answer

Since status is an ID you need to write your jquery as

$("#status").html("Hello <b>world!</b>");

Selectors in jquery begin with # for ids and . for classes.

Please refer this simple link to get an idea on how to use selectors

http://www.w3schools.com/jquery/jquery_ref_selectors.asp

Comments