Jump to content

davej

Moderator
  • Posts

    3,988
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by davej

  1. davej

    AJAX

    How about the server response? In that direction is the "Content-Type" "application/json" or not? I've been piddling with a little project for a long time but the problem is that just because something seems to work doesn't prove that it was actually done right.
  2. davej

    AJAX

    Hmmm, so if there is no advantage to including the content length why would anyone bother with that? With utf-8 strings I don't know if I can count bytes anyway. I don't see any point in not using a short key such as "json="
  3. davej

    AJAX

    The details are what I find confusing, because this is just uriencoding in the server direction, except they don't add a key such as "json=" so then at the server you can't just use $jsondata = $_POST('json') and what is the advantage of not using a key anyway? Also they don't set the header as JSON... x.setRequestHeader("Content-Type", "application/json") They don't encode the JSON even though it is being sent as urlencoded... encodeURIComponent() And when is a length used or needed? x.setRequestHeader("Content-Length", mydata.length) And then there is also the mysterious "reviver" function... JSON.parse(text[, reviver])
  4. davej

    AJAX

    I've been looking for POST JSON AJAX examples but most of them use JQuery. I don't really want JQuery unless there is some overwhelming advantage.
  5. davej

    AJAX

    So if JQuery is supposed to automatically handle all the different IE XMLHttpRequest object versions then why can't I find that code in the JQuery source? I searched jquery-3.1.0.js for "Microsoft.XMLHTTP" and found nothing. The plain vanilla Javascript code I've been looking at does this... if (window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { var versions = [ "Microsoft.XMLHTTP", "MSXML2.XMLHTTP", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.6.0" ]; for (var i=0,len=versions.length ; i<len ; i++){ try{ xmlhttp = new ActiveXObject(versions[i]); break; // breaks out of for-loop on success }catch(e){ } } } else { alert("Your browser is too old.\nUpdate your browser."); } Is there anything else significant that JQuery handles automagically to simplify AJAX?
  6. var wrapper = document.getElementById("wrapper"); wrapper.onclick = function(evt) { if (evt.target.id == 'id1'){ // id1 was clicked on }else if (evt.target.id == 'id2'){ // id2 was clicked on }else{ // something else was clicked on } }
  7. Perhaps you can install Apache?
  8. Although I own a Raspberry Pi I have not messed with it much. I suspect that there are probably Raspberry-Pi-specific forums where you might find many more people who might know these answers.
  9. Assign a handler to a parent element and then use an if statement to check the event target. http://www.w3schools.com/jsref/event_target.asp ele.onclick = function(evt) { alert(evt.target.id); }
  10. davej

    SQL Query

    It isn't clear what you are talking about. In your image there are no J2 or K2 cells. Also it isn't clear how many columns are in your INFO table or if you are describing two separate tables..
  11. Diploma for what?
  12. I deleted your table, but maybe something like this... <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <title>title</title> <style> .socialmedia{ width:200px; border:1px solid #ddd; } .facebook,.twitter{ display:inline-block; height:40px; width:40px; border-radius:20px; background-color:#06c; vertical-align:middle; text-align:center; } .twitter{ background-color: #50d; } .facebook a,.twitter a{ color:#000; font-weight:bold; text-decoration:none; vertical-align:middle; line-height:40px } </style> </head> <body> <h2>Text</h2> <div class="socialmedia"> <span class="facebook"><a href="http://www.facebook.com/davis">F</a></span> <span class="twitter"><a href="http://www.twitter.com/davis">T</a></span> </div> </body> </html>
  13. See... http://www.w3schools.com/php/php_ajax_rss_reader.asp
  14. Python is a general purpose language. We don't have a C++ tutorial either. See... http://lmgtfy.com/?q=python+language+tutorial
  15. If you use <input type="number" step="0.1"/> then 1e-2 or 0.01 will create an error because it is smaller than the step-size. You can use type="text" to avoid this issue, but then you won't have the little up-down arrows or the html range limits.
  16. <h1>Ohms Law</h1> <fieldset> <legend>V=R*I</legend> <p> <label for="ohm">Ohm (Ω)</label> <input type="number" id="ohm" step="0.1" min="0" /> <label for="ampere">Ampere (I)</label> <input type="number" id="ampere" step="0.1" min="0" /> </p> <p> <input type="button" id="btn1" value="Calculate" /> or <input type="button" id="btn2" value="Reset" /> </p> <p> <label for="volt">Volt (V)</label> <input type="text" id="volt" /> </p> </fieldset> <script> document.getElementById('btn1').onclick = handler; document.getElementById('btn2').onclick = clear; function handler(){ var r = Number(document.getElementById('ohm').value.trim()); var i = Number(document.getElementById('ampere').value.trim()); var e = i*r; document.getElementById('volt').value = e.toFixed(3); }//end of function function clear(){ document.getElementById('ohm').value = '0'; document.getElementById('ampere').value = '0'; document.getElementById('volt').value = '0'; }//end of function </script> ...OR... <h1>Ohm's Law Calculator</h1> <form id="ohmslaw" action=""> <fieldset> <legend>V=R*I</legend> <p> <label for="ohm">Ohm (Ω)</label> <input type="number" id="ohm" step="0.1" min="0" /> <label for="ampere">Ampere (I)</label> <input type="number" id="ampere" step="0.1" min="0"/> </p> <p> <input type="submit" value="Calculate" /> or <input type="reset" value="Reset" /> </p> <p> <label for="volt">Volt (V)</label> <input type="text" id="volt"/> </p> </fieldset> </form> <script> document.getElementById('ohmslaw').onsubmit = function(evt) { evt.preventDefault(); var o = parseFloat(document.getElementById('ohm').value.trim()); var a = parseFloat(document.getElementById('ampere').value.trim()); document.getElementById('volt').value = (o * a).toFixed(3); } </script>
  17. One way is to use type="text" for the input. Another way is to use type="number" with step="0.1" <input type="number" min="0" step="0.1" id="ide" value="0" />
  18. Here is a crude example. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Ohms Law</title> <style> input{ width:50px; height:25px; text-align:center; } span#idi{ display:inline-block; vertical-align:top; text-align:center; width:60px; height:25px; border:1px solid #ccc; } #wrap{ padding:15px; width:500px; height:120px; border:1px solid #bbb; font-size:20px; font-weight:bold; } </style> </head> <body> <h1>Ohms Law</h1> <div id="wrap"> <p>I = E/R</p> <span id="idi"></span>Amperes = <input type="number" min="0" id="ide" value="0" />Volts / <input type="number" min="1" id="idr" value="1" />Ohms </div> <script> document.getElementById('ide').onchange = handler; document.getElementById('idr').onchange = handler; function handler(){ var e = Number(document.getElementById('ide').value.trim()); var r = Number(document.getElementById('idr').value.trim()); var i = e/r; document.getElementById('idi').innerHTML = i.toFixed(3); }//end of function </script> </body> </html>
  19. Javascript often tries to make implicit type conversions when it believes that is what is desired, so if you are not careful you can often see unexpected results. For example if you mix strings and numbers it might guess wrong. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>tab</title> </head> <body> <h1>Assigning Values</h1> <p>JavaScript</p> <input type="number" id="ida" value="5" /> <input type="number" id="idb" value="1" /> <input type="button" id="btn1" value="Calculate"/> <div id="out1"></div> <script> document.getElementById('btn1').onclick = handler; function handler(){ var a = document.getElementById('ida').value; var b = document.getElementById('idb').value; var x = Number(a); var y = Number(; var sum = x + y; var str = "typeof: " + (typeof a) + " " + (typeof ; str += "<br/>Adding raw: " + a + b; str += "<br/>Adding raw: " + (a + ; str += "<br/>Adding numbers: " + x + y; str += "<br/>Adding numbers: " + (x + y); str += "<br/>Adding numbers: " + sum; document.getElementById("out1").innerHTML = str; }//end of function </script> </body> </html>
  20. Why don't you simply write this in Javascript?
  21. That's a little different. So maybe "dog" is replaced by <span class="lookup">dog</span> and the wrapper div for the entire page is set to call a click handler.
  22. The examples provided are usually the simplest solutions that are possible. Once you understand how they work then -- yes -- you can easily improve them.
  23. I would have asked you for an example, because this idea makes little sense to me.
  24. The basic answer for that is AJAX. See... http://www.w3schools.com/ajax/
×
×
  • Create New...