0

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();
  });
}
3
  • 1
    you can put jQuery code within your pure JS code. Only requirement is that you need to add JQuery library via <script> tag within <head> section of your HTML page. Commented Nov 3, 2016 at 4:24
  • jquery is javascript Commented Nov 3, 2016 at 4:29
  • I know but how to insert it in a bunch of javascript code. I try to insert the $("status").html("Hello <b>world!</b>"); but not work Commented Nov 3, 2016 at 4:35

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

No Problem, Glad to help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.