Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <a href="http://bit.ly/droidquery" rel="nofollow noreferrer">droidQuery</a> to perform an <code>Ajax</code> request with similar syntax to <code>Javascript</code>. It is highly configurable, so check the <a href="http://phil-brown.github.io/droidQuery/doc/self/philbrown/droidQuery/AjaxOptions.html" rel="nofollow noreferrer">javadocs</a> for help (if you have used <code>Javascript</code>, you will catch on really fast). The call will run in a background thread, but the callback methods will be called on the main thread. Here is an example of how to do a <code>post</code> that gets a <code>JSON</code> response:</p> <pre><code>$.ajax(new AjaxOptions().url("http://www.example.com") .type("post") .dataType("json") .data(bitmap_bytes) .context(this) .success(new Function() { @Override public void invoke($ droidQuery, Object... params) { JSONObject json = (JSONObject) params[0]; //handle json response. Also see $.map(JSONObject) for parsing } }) .error(new Function() { @Override public void invoke($ droidQuery, Object... params) { AjaxError e = (AjaxError) params[0]; Log.e("$", "Error: " + e.status + ": " + e.error); } })); </code></pre> <p>If you want to add a progress spinner, <a href="https://github.com/phil-brown/droidProgress" rel="nofollow noreferrer">droidProgress</a> is a <em>droidQuery Extension</em>, and can very easily be integrated with <em>droidQuery</em>.</p> <p>Also, you can see how to convert a <code>Bitmap</code> to a <code>byte[]</code> at <a href="https://stackoverflow.com/questions/4989182/converting-java-bitmap-to-byte-array">converting Java bitmap to byte array</a>.</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