Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. var JSONs = {
  2. example:['one','two','three']
  3. };
  4.  
  5. document.write(JSONs.example[0]);
  6.  
  7. $.ajax({
  8. url: "http://olympics.clearlytech.com/api/v1/medals/",
  9. success: function(data) {
  10. var json = JSON.parse(data);
  11. }
  12. });
  13.  
  14. $(document).ready(function(){
  15. alert("here");
  16. $.getJSON("http://olympics.clearlytech.com/api/v1/medals/",function(data){
  17. $.each(data,function(key,value){
  18. alert(data[key].country_name);
  19. alert(data[key].rank);
  20.  
  21. console.log(data[key].rank));
  22. });
  23. });
  24. });
  25.  
  26. public void handleResponse(String response)
  27.  
  28. {
  29. // display("Response:"+response);
  30. if(!response.equalsIgnoreCase(""))
  31. {
  32. JSONObject jso;
  33. try {
  34. jso = new JSONObject(response);
  35.  
  36.  
  37. String status = jso.getString("status");
  38. int valid=jso.getInt("valid");
  39. // display("Welcome : "+UName);
  40. if(valid>0)
  41. {
  42. if( status.equalsIgnoreCase("") || status==null || status.equalsIgnoreCase("Failed"))
  43. {
  44. invalid.setText("Invalid password");
  45. //reset();
  46. pwd.setText("");
  47. }
  48. else
  49. {
  50. //display(status);
  51. intObj=new Intent(MainActivity.this,Design_Activity.class);
  52. intObj.putExtra("Username", mUname);
  53. startActivity(intObj);
  54. MainActivity.this.finish();
  55. }
  56.  
  57. }
  58. else
  59. {
  60. invalid.setText("Invalid userid");
  61. uname.setText("");
  62. }
  63. }
  64. catch (JSONException e1) {
  65. // TODO Auto-generated catch block
  66. Log.e(TAG, e1.getLocalizedMessage(), e1);
  67. }
  68. catch(Exception e)
  69. {
  70. Log.e(TAG, e.getLocalizedMessage(), e);
  71. }
  72.  
  73.  
  74. }
  75. else
  76. {
  77. display("Could not able to reach Server!");
  78. }
  79.  
  80.  
  81. }
  82.  
  83. function getData(){
  84. // Initialize the Ajax request
  85. var xhr=new XMLHttpRequest();
  86. xhr.open('get', 'http://olympics.clearlytech.com/api/v1/medals/');
  87.  
  88. // Track the state changes of the request
  89. xhr.onreadystatechange=function(){
  90. // Ready state 4 means the request is done
  91. if(xhr.readyState === 4){
  92. // 200 is a successful return
  93. if(xhr.status === 200){
  94. alert(xhr.responseText); // 'This is the returned text.'
  95. }else{
  96. alert('Error: '+xhr.status); // An error occurred during the request
  97. }
  98. }
  99. }
  100.  
  101. // Send the request to send-ajax-data.php
  102. xhr.send(null);
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement