Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing jQuery to parse XML returned from PHP script (imgur.com API)
    primarykey
    data
    text
    <p>Here's my jQuery:</p> <pre><code>var docname = $('#doc').val(); function parseXml(xml) { $(xml).find("rsp").each(function() { alert("success"); }); } $('#submit').click(function() { $.ajax({ type: "GET", url: "img_upload.php", data: "doc=" + docname, dataType: "xml", success: parseXml }); return false; }); </code></pre> <p>Note that #doc is the id of a form text input box and #submit is the submit button's id. If successful, I'd like a simple "success" javascript popup to appear.</p> <p>Here's <em>img_upload.php</em> with my API key omitted:</p> <pre><code>&lt;?php $filename = $_GET["doc"]; $handle = fopen($filename, "r"); $data = fread($handle, filesize($filename)); // $data is file data $pvars = array('image' =&gt; base64_encode($data), 'key' =&gt; &lt;MY API KEY&gt;); $timeout = 30; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://imgur.com/api/upload.xml'); curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars); $xml = curl_exec($curl); curl_close ($curl); ?&gt; </code></pre> <p>When directly accessed with a GET argument for "doc", img_upload.php file returns the following XML format:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;rsp stat="ok"&gt; &lt;image_hash&gt;cxmHM&lt;/image_hash&gt; &lt;delete_hash&gt;NNy6VNpiAA&lt;/delete_hash&gt; &lt;original_image&gt;http://imgur.com/cxmHM.png&lt;/original_image&gt; &lt;large_thumbnail&gt;http://imgur.com/cxmHMl.png&lt;/large_thumbnail&gt; &lt;small_thumbnail&gt;http://imgur.com/cxmHMs.png&lt;/small_thumbnail&gt; &lt;imgur_page&gt;http://imgur.com/cxmHM&lt;/imgur_page&gt; &lt;delete_page&gt;http://imgur.com/delete/NNy6VNpiAA&lt;/delete_page&gt; &lt;/rsp&gt; </code></pre> <p>What's the problem here? Here's the <a href="http://code.google.com/p/imgur-api/wiki/ImageUploading" rel="nofollow noreferrer">Imgur API page</a> for reference.</p>
    singulars
    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.
 

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