Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP proxy jQuery part to javascript
    text
    copied!<p>Here is code that is done in jQuery and the aim is to change it to javascript. The original code is from here: <a href="http://benalman.com/code/projects/php-simple-proxy/examples/simple/" rel="nofollow">php proxy</a></p> <p>Here is the jQuery to change to javascript:</p> <pre><code>$(function(){ // Handle form submit. $('#params').submit(function(){ var proxy = 'ba-simple-proxy.php', url = proxy + '?' + $('#params').serialize(); // Make GET request. $.get( url, function(data){ $('#response') .html( '&lt;pre class="brush:xml"/&gt;' ) .find( 'pre' ) // To make the lines proper and to frame the text. .text( data ); }); // Prevent default form submit action. return false; }); }); </code></pre> <p>And below is the same code in javascript, which is not ready yet. The problem is that it is not logical at the moment.</p> <p>The form bit of html which is not included here calls ajaxcontent(). ajaxcontent() creates the ".html" and ".text" part of the jQuery. JQuery ".find" can be ignored at the moment.</p> <p>In ajaxcontent() the "pre" tag is created first, then added class "brush:xml" in it. Then "createTextNode" adds the source coude from the page that is asked. This is the "( data )" in jQuery. Here the code fails, since ajax wants to place the information to id="response", but ajaxcontent() still needs to do this line "xelement.appendChild(xtext);" to attach the text to "xelement".</p> <pre><code>function loadajax() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("response").innerHTML=xmlhttp.responseText; } } var urlvar=(document.getElementById("url").value) xmlhttp.open("GET","ba-simple-proxy.php&amp;url="+urlvar,true); xmlhttp.send(); } function ajaxcontent() { var xelement=document.createElement("pre"); xelement.className="brush:xml"; var xtext=document.createTextNode( loadajax() ); xelement.appendChild(xtext); } </code></pre> <p>Any suggestions how to make this work? The jQuery part is a working example but the javascript part is not yet.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload