xmlhttp not working - xmlhttprequest

I'm not sure what I am doing wrong. I placed this in the body, next to the div myDiv and it seems not to run, so I don't know what I am doing wrong.
<script type="text/javascript" language="javascript">
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://www.example.com/test.php",false);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
</script>
<div id="myDiv"></div>

The script runs before the div "myDiv" is rendered. Swap them over...
<div id="myDiv"></div>
<script type="text/javascript" language="javascript">
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://www.example.com/test.php",false);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

Related

YouTube iFrame API “setPlaybackQuality” not working

YouTube iFrame API “setPlaybackQuality” not working.i want to change video qulity to lowest.but i cant change it by the api.i used player.setPlaybackQuality('small').it not worked.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<button id="change_quality">Change Quality</button>
<div id="player"></div>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: '6LV3JdR5aZw',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
$("#change_quality").click(function() {
event.target.playVideo();
var d=player.getPlaybackQuality()
console.log("before");
console.log(d);
player.setPlaybackQuality('small')
var v=player.getPlaybackQuality()
console.log("after");
console.log(v);
});
}
}
</script>
</body>
</html>
it is not working in youtube demo also
Demo

FB.login() results in auto-login popup before on-click

I'm developing sns login page.
I use custom login-button and FB.login().
Suddenly, I encounted unsuspected problem that FB.login() resulted in auto-login popup before I click login button..
I do Not want pop-up login window before click the login-button...!!
How can I fix this problem?? Help me..plz....ㅜㅜ
this is my url!
http://sangji.dothome.co.kr/index2.html
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function(){
FB.init({
appId: 'myAppKey',
status: true,
cookie: true,
xfbml: true,
oauth: true,
version : 'v2.5'
});
fbLoginStatus();
};
(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/ko_KR/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function fbLoginStatus(){
FB.getLoginStatus(function(response) {
console.log(response);
if (response.status === 'connected') {
var access_token = FB.getAuthResponse()['accessToken'];
console.log(access_token);
} else {
fblogin();
}
});
}
function fblogin(){
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log(access_token);
} else {
console.log('Authorization failed.');
}
},{ //permissions
scope: 'email'
});
}
</script>
<img src="fb_bt.png">
</body>
</html>
You are calling 'fblogin' in the callback to getLoginStatus - this in turn is calling FB.login which is based on opening a popup.

Facebook login with JS

I'm trying to get a login via Javascript SDK from Facebook.
I just have never done something like that.
So this is my source code:
<html>
<head>
</head>
<body>
<script type="text/javascript">
window.fbAsyncInit=function(){
FB.init({
appId : '1234567890',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(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/es_LA/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log('Logged in.');
}
else {
console.log('Logging in...');
FB.login();
}
});
</script>
<input type="button" onClick="FB.getLoginStatus();" value="Login" />
</body>
</html>
But sadly this is doing... nothing :(
There is nothing I can see in the console and nothing displayed (even if I push the Login-Button)
Maybe someone could help me?!
Best regards,
Kartilia

What are the requirements to the type of XMLHttpRequest.onreadystatechange's status parameter

Do any standards require that the type of the status parameter in the XMLHttpRequest's readystatechange event is "number"?
SockJs-0.3.4 expects to be able to say
if (status === 200) {
but when running under Intel XDK's App Framework, the type of the status is "string".
Who is mistaken?
Here is a small test case that shows the problem:
<!DOCTYPE html>
<html>
<head>
<script src='intelxdk.js'></script>
<script src='cordova.js'></script>
<script src='xhr.js'></script>
<script type="application/javascript" src="js/appframework.min.js"></script>
<script type="text/javascript">
$(function(){
$('#test').click(function () {
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://graph.facebook.com/", true);
xhr.onreadystatechange = function() {
switch (xhr.readyState) {
case 4:
var status = xhr.status;
alert("Type of status is: "+typeof status+". Status is: "+status+". 'status===400' is "+(status===400)+".");
break;
}
};
xhr.send();
});
});
</script>
</head>
<body>
<input type="button" id="test" value="test"/>
</body>
</html>

Getting error TypeError: document.getElementById(...) is null as function is called for the second time

I am using this code
<script type="text/javascript">
function loadXMLDoc()
{
var testValue = document.getElementById("test").value;
document.getElementById("test").value = ++testValue;
var testValue2 = document.getElementById("test").value;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("3");
document.getElementById("loading").style.display = "none";
alert("4");
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
alert("1");
document.getElementById("loading").style.display = "block";
alert("2");
xmlhttp.open("GET","catalog/view/theme/default/template/information/latest_newsroom.php?q="+testValue2,true);
xmlhttp.send();
}
</script>
<form name="testForm" method="post" action="">
<input type="text" name="test" id="test" value="1" />
<input type="button" name="testButton" value="More" onclick="loadXMLDoc()" />
</form>
and it gives the error :
TypeError: document.getElementById(...) is null
as my function runs for the second time.
The error is corect.
You have set var testValue = document.getElementById("test").value;
so this document.getElementById("test").value = ++testValue;
should be testValue.value = ++testValue; since testValue is now a variable.
Below is what i have sugested in the comment:
<script type="text/javascript">
function loadXMLDoc()
{
var testValue = document.getElementById("test").value;
document.getElementById("test").value = ++testValue;
var testValue2 = document.getElementById("test").value;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("3");
document.getElementById("loading").style.display = "none";
alert("4");
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
else
{
document.getElementById("loading").style.display = "block";
}
}
alert("1");
alert("2");
xmlhttp.open("GET","catalog/view/theme/default/template/information/latest_newsroom.php?q="+testValue2,true);
xmlhttp.send();
}
</script>
<form name="testForm" method="post" action="">
<input type="text" name="test" id="test" value="1" />
<input type="button" name="testButton" value="More" onclick="loadXMLDoc()" />
</form>