I am trying to get data returned by AJAX after success. But It's returning the whole Javascript which I am echoing in the PHP file. What I really need is just the words which my JS is printing on the page.
Here is the Javascript code -
window.fbAsyncInit = function() {
FB.init({appId: 'xxxxxxxxxxx', status: true, cookie: true});
FB.getLoginStatus(function(o) {
if (!o && o.status) return;
if (o.status == 'connected') {
document.write("connected");
} else if (o.status == 'not_authorized') {
document.write("unauthorized");
} else {
document.write("loggedOut");
}
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
I want to compare the returned data (data== connected, not_authorized, loggedOut)
and show respective html elements after comparing the returned data with if..else
in AJAX success.
I would be thankful if someone helps me out of this problem.
Thank you.
Your question is a little ambiguous and I would suggest posting the entire context.
I'll hazard a guess anyways. It seems as if you are trying to execute the Javascript after a successful AJAX call but in a PHP file. That won't work because JS only executes in a browser context. You can either execute and return plain strings from your PHP or you can use JSONP and the function you have pasted in the callback.