var sw = new Stopwatch();
sw.Start();
await MySuperCoolJobAsync();
sw.Stop();
Trace.WriteLine($"{sw.ElapsedMilliseconds} мс");
/**
* Выполняет GET запрос к http-серверу,
* возвращает JSONArray, либо JSONObject */
public static Object getJsonFromServer(String relativeUrl) throws Exception {
URL url = new URL("http://example.com/" + relativeUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
int statusCode = con.getResponseCode();
if (statusCode != HttpURLConnection.HTTP_OK)
throw new IOException(con.getResponseMessage() + " (HTTP " + statusCode + ")");
BufferedReader reader = new BufferedReader(new InputStreamReader(
con.getInputStream(), Charset.forName("utf-8")));
StringBuilder sb = new StringBuilder();
try {
String line;
while ((line = reader.readLine()) != null)
sb.append(line);
} finally {
reader.close();
}
String text = sb.toString();
if (TextUtils.isEmpty(text))
return null;
return new JSONArray("[" + text + "]").get(0);
}
document.addEventListener('DOMContentLoaded', function () {
function getlike(id) {
var like = $('#like_' + id);
// ...
}
});
$('span[id^="like_"]').each(function(index, like) {
var id = like.id;
// ...
});