Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pass attribute in form <code>{url:"",method:"",data:{...},callback:function(){}}</code></p> <pre><code>var ajax=function(){ try{ var xml =new XMLHttpRequest(); var args =arguments; var context =this; var multipart =""; xml.open(args[0].method,args[0].url,true); if(args[0].method.search(/post/i)!=-1){ var boundary=Math.random().toString().substr(2); xml.setRequestHeader("content-type", "multipart/form-data; charset=utf-8; boundary=" + boundary); for(var key in args[0].data){ multipart += "--" + boundary + "\r\nContent-Disposition: form-data; name=" + key + "\r\nContent-type: application/octet-stream" + "\r\n\r\n" + args[0].data[key] + "\r\n"; } multipart += "--"+boundary+"--\r\n"; } xml.onreadystatechange=function(){ try{ if(xml.readyState==4){ context.txt=xml.responseText; context.xml=xml.responseXML; args[0].callback(); } } catch(e){} } xml.send(multipart); } catch(e){} } </code></pre> <p>If you want to get back response you can use this</p> <pre><code>var response={}; ajax.call(response,{...args...}) </code></pre> <p>and you can retrieve all data by <code>response.txt</code> or <code>response.xml</code></p> <p><strong>A bit late update</strong></p> <p>As for @Varun question about <code>&lt;input type='file'&gt;</code> uploads, this code can't handle file uploads directly, in order to send files using this code, you need to perform preprocessing of the raw file data using <a href="https://developer.mozilla.org/en-US/docs/Web/API/File">File API</a> to get non-binary streams (like base64 or any other bin2hex-like form).</p> <p>But, since it's a 2015 year, I can suggest to move from the construction of the multipart streams to something a bit more robust, like the <a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData">FormData API</a>.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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