Praveen Kumar

Praveen Kumar

  • NA
  • 60
  • 2.4k

how to handle null point exception?

Aug 6 2018 4:08 AM
  1. $(document).ready(function(){  
  2. try{  
  3. ExecuteOrDelayUntilScriptLoaded(downloads, "sp.js");  
  4. }  
  5. catch(e)  
  6. {  
  7. alert(JSON.stringify(e));  
  8. }  
  9. });  
  10. function downloads() {  
  11. var pagename = window.location.href.split('/').reverse()[0];  
  12. $.ajax({  
  13. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('DownloadLinks')/items?$filter=CategoryDownload eq '"+ pagename +"'&$orderby=Order_ID asc",  
  14. type: "GET",  
  15. headers: {  
  16. "accept""application/json;odata=verbose",  
  17. "content-type""application/json;odata=verbose",  
  18. },  
  19. success: DownloadLinksSucceeded,  
  20. error: DownloadLinksFailed  
  21. });  
  22. }  
  23. var results1;  
  24. var banner;  
  25. function DownloadLinksSucceeded(data) {  
  26. console.log(data);  
  27. results1 =data.d.results;  
  28.    
  29. var htmlString="<div class='Category_heading'><h2 class='Category_heading1'>DOWNLOADS</h2></div>";  
  30.    
  31. htmlString+="<ul class='no_bullet text'>";  
  32. for(var i=0; i< results1.length; i++){  
  33. var item1= results1[i];  
  34. htmlString += '<li class="image">';  
  35. htmlString += '<a nowrap class="link_tag" href="'+ results1[i].DownloadURL.Url +'">';  
  36. htmlString += results1[i].Title;  
  37.    
  38. if(results1[i].Banner_Image.Url!=null)  
  39. {  
  40. var banner=results1[i].Banner_Image.Url;  
  41. htmlString +='<img class="baner_image" src="'+banner+'" alt="">';  
  42. }  
  43. else  
  44. {  
  45. alert('hello');  
  46. }  
  47.    
  48. htmlString += '</a>';  
  49. htmlString+='</li>';  
  50. //htmlString += '<a class="link_tag" href="'+ results1[i].DownloadURL.Url +'">'+ results1[i].Title +'</a>';  
  51. }  
  52. htmlString+="</ul>";  
  53. $("#download1").html(htmlString);  
  54. }  
  55. function DownloadLinksFailed() {  
  56. alert('Sorry An Error Has Occurred!');  
  57. }  

Attachment: New_Text_Document.zip

Answers (8)