Note that there are some explanatory texts on larger screens.

plurals
  1. POSending HTML as javascript variable through getJSON doesn't work
    primarykey
    data
    text
    <p>I've seen some questions about sending HTML data <em>from</em> PHP <em>to</em> an HTML page, but this question is actually for the contrary (I can get HTML from PHP fine with json_encode).</p> <p>A small snippet of code that explains most of it:</p> <pre><code>savePage = function() { var pagecontents = $("#editcontents").val(); log("Attempting to save page..."); $.getJSON(docTools+"?jsoncallback=?",{action:'update', loginCookie:loginCookie, page:thisFile, newdata:pagecontents}, function(data) { if(data.response[0].answer === 'true') { log('Page'+thisFile+' was saved correctly: '+data.response[0].details); $("#editcontents, #saveedit, #canceledit").remove(); $("#bodycontents").html(pagecontents); } else { log('Failed to save page. Error (' + data.response[0].errorcode + ') : ' + data.response[0].errormessage); } }); } </code></pre> <p>FYI: log just does console.log if it exists.</p> <p>So basically what happens here is that the <strong>pagecontents</strong> variable contains HTML data, all within a <code>&lt;body&gt;</code> tag (meaning no header information if that matters). However, when I actually call this function, the log() function works fine... but the getJSON() never completes (actually, as far as I can tell it never makes it to my PHP server).</p> <p>If I replace <strong>pagecontents</strong> with just a standard string, it works fine.</p> <p>Do I need to do something akin to json_encode from javascript before sending? Something that would convert everything to html entities?</p> <p><strong>--Edit--</strong></p> <p>So I just discovered the "Net" tab in Firebug and it's showing me something I hadn't realized: it shows the GET request with all the proper data... But the server returns a 404. I don't know how that could happen since the PHP file is the same one that I grab stuff from 5 seconds before.</p> <p>Also, even though I tried to change .getJSON() with .post(...,'json') , Firebug is still showing a GET request, not a POST, so it's got me even more confused now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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