• Questions That Don't Need Their Own Thread v3
    4,068 replies, posted
  • [QUOTE=pureparanoid;35630568]Since I know nothing about javascript, can someone be a bro and fix up this script I used to use that is broken because of youtube updates? Thanks for your time guys. [url]http://pastebin.com/Py1iV6fA[/url][/QUOTE] Do you have something like Firebug? And what's the error?
  • [QUOTE=pureparanoid;35630568]Since I know nothing about javascript, can someone be a bro and fix up this script I used to use that is broken because of youtube updates? Thanks for your time guys. [url]http://pastebin.com/Py1iV6fA[/url][/QUOTE] Your jQuery selectors are off (You need to start your selector with a "#" if it's an ID or a "." if it's a class. Plus you don't have jQuery embedded anywhere in there so the code won't work until you do.
  • [QUOTE=douche beat;35638253]Your jQuery selectors are off (You need to start your selector with a "#" if it's an ID or a "." if it's a class. Plus you don't have jQuery embedded anywhere in there so the code won't work until you do.[/QUOTE] He's right, but keep in mind to exclude those prefixes when selecting elements by tag name.
  • I've written a PHP script which pulls a random set of data from a database, and I'd like to know how to echo this onto a page with AJAX/Javascript. Can anyone point me in the right direction?
  • [QUOTE=Slater;35647483]I've written a PHP script which pulls a random set of data from a database, and I'd like to know how to echo this onto a page with AJAX/Javascript. Can anyone point me in the right direction?[/QUOTE] ajax.php [php] <?php header('Content-Type: application/json'); // jQuery will check for this header and decode the json. echo json_encode(array( 'hello' => 'world', 'foo' => 'bar' )); [/php] script.js (requires jQuery) [code] $.ajax('ajax.php', function(data){ alert('Hello ' + data.hello + '!'); }); [/code]
  • [QUOTE=Jelly;35647537]ajax.php [php] <?php header('Content-Type: application/json'); // jQuery will check for this header and decode the json. echo json_encode(array( 'hello' => 'world', 'foo' => 'bar' )); [/php] script.js (requires jQuery) [code] $.ajax('ajax.php', function(data){ alert('Hello ' + data.hello + '!'); }); [/code][/QUOTE] Sadly, I'm not able to use jQuery (University workshop task) and I'd like to learn how it's coded in pure PHP/Javascript/AJAX. Thanks for the quick response though.
  • [QUOTE=Slater;35647596]Sadly, I'm not able to use jQuery (University workshop task) and I'd like to learn how it's coded in pure PHP/Javascript/AJAX. Thanks for the quick response though.[/QUOTE] Cross-browser AJAX is a pain in the ass because many browsers implement it differently and you end up having a spaghetti code of try and catches.
  • Here's a XMLHttpRequest wrapper that works in most browsers: [url]http://www.quirksmode.org/js/xmlhttp.html[/url] In use: [code] var json = (sendRequest('ajax.php', function(req){ return JSON.parse(req.responseText); }))(); [/code]
  • [QUOTE=Jelly;35647686]Cross-browser AJAX is a pain in the ass because many browsers implement it differently and you end up having a spaghetti code of try and catches.[/QUOTE] It's not [i]that[/i] bad. [code]// From http://en.wikipedia.org/wiki/XMLHttpRequest#Support_in_Internet_Explorer_versions_5.2C_5.5_and_6 if (typeof XMLHttpRequest == "undefined") { XMLHttpRequest = function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {} try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} //Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant throw new Error("This browser does not support XMLHttpRequest."); }; } var client = new XMLHttpRequest(); client.onreadystatechange = function() { if (client.readyState == 4 && client.status == 200) { var data = JSON.parse(client.responseText); // Include json2.js from https://github.com/douglascrockford/JSON-js alert('Hello ' + data.hello + '!'); } } client.open('GET', 'ajax.php', true); client.send(null);[/code] Should work in all major browsers (including IE 6), assuming that you've included json2.js (otherwise replace JSON.parse with eval).
  • JSON encode/decode is native in modern browsers but some older ones (ie6, ie7) don't support it. You'll need to include a javascript implementation for it. [url]https://github.com/douglascrockford/JSON-js/blob/master/json2.js[/url] Include it if it doesn't exist: [code] (function(w,d){ w.JSON || d.write('<script src="js/json2.js"><\/script>') })(window, document); [/code]
  • Can I ask questions that are not about the actual programming, but about the layout and stuff here?
  • [QUOTE=GiggityGoo;35649090]Can I ask questions that are not about the actual programming, but about the layout and stuff here?[/QUOTE] Yes.
  • I can't really use external libraries, so jQuery is out of the question. Sorry guys.
  • [QUOTE=GiggityGoo;35649090]Can I ask questions that are not about the actual programming, but about the layout and stuff here?[/QUOTE] Of course. [editline]21st April 2012[/editline] [QUOTE=Slater;35649307]I can't really use external libraries, so jQuery is out of the question. Sorry guys.[/QUOTE] They didn't post jQuery.
  • With all of the knowledge I had, I made this page. As you can see it's pretty simple still, but the microphone fills up a little of the emptiness I think. [IMG]http://i43.tinypic.com/t0k9ds.jpg[/IMG] Unfortunatly, the other pages are still so empty in my eyes. [IMG]http://i41.tinypic.com/20av1op.jpg[/IMG] Any ideas how to fill a bit of the space left up? Thanks in advance! (the pictures will be replaced.)
  • [QUOTE=GiggityGoo;35649429]With all of the knowledge I had, I made this page. As you can see it's pretty simple still, but the microphone fills up a little of the emptiness I think. [IMG]http://i43.tinypic.com/t0k9ds.jpg[/IMG] Unfortunatly, the other pages are still so empty in my eyes. [IMG]http://i41.tinypic.com/20av1op.jpg[/IMG] Any ideas how to fill a bit of the space left up? Thanks in advance! (the pictures will be replaced.)[/QUOTE] Make the menu or the content field larger.
  • [QUOTE] They didn't post jQuery.[/QUOTE] Oh? I thought they used an external library though.
  • [QUOTE=Slater;35650417]Oh? I thought they used an external library though.[/QUOTE] Nope. Just a few functions is all. Even if one of us posted a library, you could just rewrite your own from the source as example. Think a little bit.
  • [QUOTE=jaybuz;35650946]Nope. Just a few functions is all. Even if one of us posted a library, you could just rewrite your own from the source as example. Think a little bit.[/QUOTE] You're right. My apologies! I've figured it out in the mean time. If you want me to I'll share what I did.
  • [QUOTE=Slater;35651144]You're right. My apologies! I've figured it out in the mean time. If you want me to I'll share what I did.[/QUOTE] A share would be nice * interested face* :)
  • Okay so here it goes: [CODE] // Browser determination section up here (Is it firefox, safari, IE?...) httpRequest.onreadystatechange = function() { var specialOfferDiv = document.getElementById('special_offer'); document.getElementById("special_offer").innerHTML = httpRequest.responseText; }; httpRequest.open("GET", "getOffers.php", true); httpRequest.send(); [/CODE] PHP reference (getOffers.php): [CODE] <?php include_once("db_connect.php"); $sql = "big long sql statement"; $rsOffer = mysql_query( $sql ); $offer = mysql_fetch_assoc($rsOffer); echo $offer['offer']; ?> [/CODE] Apologies for the awful formatting - it looks better in Notepad++, I swear!
  • Lack of JSON makes me sad. BTW, you forgot to use your specialOfferDiv variable
  • Good point, I just re-did it haha. I'll look into JSON for the next time, it was more of a personal goal to do it without anything else : ) I'm now figuring out the setInterval command - and so far all I've managed to do is destroy my browser after 9 iterations haha.
  • This is the only place I could think of to ask but, does this page's javascript do anything weird with facebook and twitter? [code]<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script type="text/javascript"> //<![CDATA[ try{if (!window.CloudFlare) { var CloudFlare=[{verbose:0,p:0,byc:0,owlid:0,mirage:0,oracle:0,paths:{cloudflare:"/cdn-cgi/nexp/v=1443929931/"},atok:"0c11c11e8ed5801994f5be9edb6004f0",zone:"boxulo.us",rocket:"a",apps:{"ga_key":{"ua":"UA-27478034-1","ga_bs":"2"}}}];document.write('<script type="text/javascript" src="//ajax.cloudflare.com/cdn-cgi/nexp/v=3368044129/cloudflare.min.js"><'+'\/script>')}}catch(a){}; //]]> </script> <script type="text/javascript"> //<![CDATA[ window.__CF=window.__CF||{};window.__CF.AJS={"ga_key":{"ua":"UA-27478034-1","ga_bs":"2"}}; //]]> </script> <title>404 - Not Found</title> <script type="text/javascript"> /* <![CDATA[ */ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-27478034-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); (function(b){(function(a){"__CF"in b&&"DJS"in b.__CF?b.__CF.DJS.push(a):"addEventListener"in b?b.addEventListener("load",a,!1):b.attachEvent("onload",a)})(function(){"FB"in b&&"Event"in FB&&"subscribe"in FB.Event&&(FB.Event.subscribe("edge.create",function(a){_gaq.push(["_trackSocial","facebook","like",a])}),FB.Event.subscribe("edge.remove",function(a){_gaq.push(["_trackSocial","facebook","unlike",a])}),FB.Event.subscribe("message.send",function(a){_gaq.push(["_trackSocial","facebook","send",a])}));"twttr"in b&&"events"in twttr&&"bind"in twttr.events&&twttr.events.bind("tweet",function(a){if(a){var b;if(a.target&&a.target.nodeName=="IFRAME")a:{if(a=a.target.src){a=a.split("#")[0].match(/[^?=&]+=([^&]*)?/g);b=0;for(var c;c=a[b];++b)if(c.indexOf("url")===0){b=unescape(c.split("=")[1]);break a}}b=void 0}_gaq.push(["_trackSocial","twitter","tweet",b])}})})})(window); /* ]]> */ </script> </head> <body> <h1>404 - Not Found</h1> </body> </html>[/code]
  • [QUOTE=Richy19;35654222]This is the only place I could think of to ask but, does this page's javascript do anything weird with facebook and twitter? [/QUOTE] no. it's just Cloudflares tracking code.
  • [QUOTE=RusselG;35655075]no. it's just Cloudflares tracking code.[/QUOTE] And Google Analytics.
  • [QUOTE=Jelly;35656363]And Google Analytics.[/QUOTE] To me it looks like it does something with facebook AND twitter: [CODE](function(b){(function(a){"__CF"in b&&"DJS"in b.__CF?b.__CF.DJS.push(a):"addEventListener"in b?b.addEventListener("load",a,!1):b.attachEvent("onload",a)})(function(){"FB"in b&&"Event"in FB&&"subscribe"in FB.Event&&(FB.Event.subscribe("edge.create",function(a){_gaq.push(["_trackSocial","facebook","like",a])}),FB.Event.subscribe("edge.remove",function(a){_gaq.push(["_trackSocial","facebook","unlike",a])}),FB.Event.subscribe("message.send",function(a){_gaq.push(["_trackSocial","facebook","send",a])}));"twttr"in b&&"events"in twttr&&"bind"in twttr.events&&twttr.events.bind("tweet",function(a){if(a){var b;if(a.target&&a.target.nodeName=="IFRAME")a:{if(a=a.target.src){a=a.split("#")[0].match(/[^?=&]+=([^&]*)?/g);b=0;for(var c;c=a[b];++b)if(c.indexOf("url")===0){b=unescape(c.split("=")[1]);break a}}b=void 0}_gaq.push(["_trackSocial","twitter","tweet",b])}})})})(window);[/CODE] Although I can't find anywhere in the code where it submits data.
  • [QUOTE=rookwood101;35658269]To me it looks like it does something with facebook AND twitter: [CODE](function(b){(function(a){"__CF"in b&&"DJS"in b.__CF?b.__CF.DJS.push(a):"addEventListener"in b?b.addEventListener("load",a,!1):b.attachEvent("onload",a)})(function(){"FB"in b&&"Event"in FB&&"subscribe"in FB.Event&&(FB.Event.subscribe("edge.create",function(a){_gaq.push(["_trackSocial","facebook","like",a])}),FB.Event.subscribe("edge.remove",function(a){_gaq.push(["_trackSocial","facebook","unlike",a])}),FB.Event.subscribe("message.send",function(a){_gaq.push(["_trackSocial","facebook","send",a])}));"twttr"in b&&"events"in twttr&&"bind"in twttr.events&&twttr.events.bind("tweet",function(a){if(a){var b;if(a.target&&a.target.nodeName=="IFRAME")a:{if(a=a.target.src){a=a.split("#")[0].match(/[^?=&]+=([^&]*)?/g);b=0;for(var c;c=a[b];++b)if(c.indexOf("url")===0){b=unescape(c.split("=")[1]);break a}}b=void 0}_gaq.push(["_trackSocial","twitter","tweet",b])}})})})(window);[/CODE] Although I can't find anywhere in the code where it submits data.[/QUOTE] that's a cloudflare script
  • What is the best way of creating a logo or text out of photographed text? This image in my case: [IMG]http://i.imgur.com/brCe1.png[/IMG]