Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

JQuery
Home›JQuery›Load Contents From Text File using jQuery

Load Contents From Text File using jQuery

By SibeeshVenu
March 29, 2015
1712
0
Share:

Introduction

Hi all, this article explains how to load the contents from a text file using jQuery and style the contents.

Background

I wanted to load same contents in various pages. For example the article links in my blog. The problem here is, I can’t use a master page since I have not included ASP.Net in my hosting plan and the next problem is I have not included a database also. My blog is entirely based on normal HTML pages. So I thought of entering the href tags in a text file and loading those href tags in the pages accordingly.

That’s all.

Create a text file

I have put some of my article links in a text file as shown below.

  1. <a target=“_blank” href=“compress-xml-string-variables-in-client-side-and-export-in.html”>
  2.    Compress XML, String, Variables in Client Side and Export in HTML5 Using jQuery
  3. </a>myBreak
  4. <a target=“_blank” href=“Infosys-Interview-Questions-For-DotNet-Professionals.html”>
  5.    Infosys Interview Questions for Dot Net Professionals
  6. </a>myBreak
  7. <a target=“_blank” href=“Using-GitHub-Application-in-Windows.html”>
  8.    Upload your Source Code to GitHub using GitHub Application in Windows
  9. </a>myBreak
  10. <a target=“_blank” href=“dot-net-interview-questions-for-experienced-and-fresher.html”>
  11.    Interview Questions For Experienced and Beginner .NET Professionals
  12. </a>myBreak
  13. <a target=“_blank” href=“export-hierarchical-html-multi-level-html-with-styles.html”>
  14.    Export Hierarchical (Multi-Level) HTML Table With Styles Using jQuery
  15. </a>myBreak
  16. <a target=“_blank” href=“how-to-make-your-website-loads-faster.html”>
  17.    How to Make Your Website Load Faster
  18. </a>myBreak
  19. ———————–
  20. <a target=“_blank” href=“Convert-CellSet-to-HTML-table-And-From-HTML-To-Json-To-Array.html”>
  21.    Convert CellSet to HTML Table and From HTML to JSON and to Array
  22. </a>myBreak

Please note that I have used a separator in each href tag. That is “myBreak”. Please download the attachment, myContents, for more information.

Load a jQuery reference

  1. <script src=“jquery-2.1.3.min.js”></script>

You can get this file from the source code attached here.

Write the script

The following is the script block I have written for the requirements.

  1. <script type=“text/javascript”>
  2.         $(document).ready(function () {
  3.             $.get(‘myContents.txt’, function (data) {
  4.                 var myHrefCollection = ‘<ul>’;
  5.                 var myData = data.split(“myBreak”);
  6.                 for (i = 0; i < myData.length; i++) {
  7.                     if (myData[i] != null || myData[i] != undefined)
  8.                         myHrefCollection += ‘<li>’ + myData[i] + ‘</li>’;
  9.                 }
  10.                 myHrefCollection += ‘</ul>’;
  11.                 $(‘#container’).html(myHrefCollection);
  12.             });
  13.         });
  14.     </script>

In the preceding script we are taking the contents from the text file using the get method of jQuery. And once the data is retrieved, we are splitting the data. To do that we are using a separator (myBreak) in our content.

Add CSS

Add the following CSS styles.

  1. <style>
  2.         a {
  3.             display: block;
  4.             margin: 0;
  5.             padding: 5px 10px 5px 20px;
  6.             color: #777777;
  7.             text-decoration: none;
  8.             border-bottom: 1px dotted #666666;
  9.             background: url(“orange_file.gif”) no-repeat 10px center #F9F9F9;
  10.             outline: none;
  11.         }
  12.         ul {
  13.             margin: 0;
  14.             padding: 0;
  15.             list-style: none;
  16.         }
  17.         li {
  18.             margin: 0 0 3px 0;
  19.             padding: 0;
  20.             display: list-item;
  21.             text-align: -webkit-match-parent;
  22.         }
  23.         #container {
  24.             display: block;
  25.             width: 700px;
  26.             padding: 25px;
  27.             background-color: #F9F9F9;
  28.             margin-bottom: 30px;
  29.         }
  30.     </style>

Output

Conclusion

Please download the source code for more details. I hope you liked this article. Now please share your thoughts and suggestions. It matters a lot.

Kindest Regards,

Sibeesh Venu

www.sibeeshpassion.com

TagsJQueryLoad contentsText from file
Previous Article

Mail Merge in Word 2013

Next Article

Configuring Mobile Services In Microsoft Azure

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0

SibeeshVenu

I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

Related articles More from author

  • Remove an array element by its index
    CodeProjectJQuery

    Remove An Array Element By Index

    August 7, 2015
    By SibeeshVenu
  • Drag and Drop the Legend and Maintain the Position in Chart
    HighChartProducts

    Drag and Drop the Legend and Maintain the Position in Chart

    April 29, 2015
    By SibeeshVenu
  • CodeProjectJQuery

    Load Data on Scroll Using jQuery

    June 30, 2015
    By SibeeshVenu
  • Code SnippetsJQuery

    Check Whether a check box is checked or not in JQuery

    May 31, 2015
    By SibeeshVenu
  • HighChart

    Working With Charts

    April 29, 2015
    By SibeeshVenu
  • Code SnippetsJQuery

    Find out the nth element and get the particular string

    May 31, 2015
    By SibeeshVenu
0

My book

Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

YouTube

MICROSOFT MVP (2016-2022)

profile for Sibeesh Venu - Microsoft MVP

Recent Posts

  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
  • Easily move data from one COSMOS DB to another
  • .NET 8 New and Efficient Way to Check IP is in Given IP Range
  • Async Client IP safelist for Dot NET
  • Post Messages to Microsoft Teams Using Python
  • Get Azure Blob Storage Blob Metadata Using PowerShell
  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
  • Integrate Azure App Insights in 1 Minute to .Net6 Application
  • Azure DevOps Service Connection with Multiple Azure Resource Group

Tags

Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
  • .NET
  • Achievements
  • ADO.NET
  • Android
  • Angular
  • Arduino
  • Article Of The Day
  • ASP.NET
  • Asp.Net Core
  • Automobile
  • Awards
  • Azure
  • Azure CDN
  • azure devops
  • Blockchain
  • Blog
  • Browser
  • C-Sharp Corner
  • C#
  • Career Advice
  • Code Snippets
  • CodeProject
  • Cognitive Services
  • Cosmos DB
  • CSS
  • CSS3
  • Data Factory
  • Database
  • Docker
  • Drawings
  • Drill Down Chart
  • English
  • Excel Programming
  • Exporting
  • Facebook
  • Fun
  • Gadgets
  • GitHub
  • GoPro
  • High Map
  • HighChart
  • How to
  • HTML
  • HTML5
  • Ignite UI
  • IIS
  • Interview
  • IoT
  • JavaScript
  • JQuery
  • jQuery UI
  • JQWidgets
  • JQX Grid
  • Json
  • Knockout JS
  • Linux
  • Machine Learning
  • Malayalam
  • Malayalam Poems
  • MDX Query
  • Microsoft
  • Microsoft ADOMD
  • Microsoft MVP
  • Microsoft Office
  • Microsoft Technologies
  • Microsoft Windows
  • Microsoft Windows Server
  • Mobile
  • MongoDB
  • Monthly Winners
  • MVC
  • MVC Grid
  • MySQL
  • News
  • Node JS
  • npm
  • Number Conversions
  • October 2015
  • Office 365
  • Office Development
  • One Plus
  • Outlook
  • Page
  • PHP
  • Poems
  • PowerShell
  • Products
  • Q&A
  • Raspberry PI
  • React
  • SEO
  • SharePoint
  • Skype
  • Social Media
  • Software
  • Spire.Doc
  • Spire.PDF
  • Spire.XLS
  • SQL
  • SQL Server
  • SSAS
  • SSMS
  • Storage In HTML5
  • Stories
  • Third Party Software Apps
  • Tips
  • Tools
  • Translator Text
  • Uncategorized
  • Unit Testing
  • UWP
  • VB.Net
  • Videos
  • Virtual Machine
  • Visual Studio
  • Visual Studio 2017
  • Wamp Server
  • Web API
  • Web Platform Installer
  • Webinars
  • WebMatrix
  • Windows 10
  • Windows 7
  • Windows 8.1
  • Wordpress
  • Writing

ABOUT ME

I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

Contact Me

  • info@sibeeshpassion.com

Pages

  • About
  • Search
  • Privacy Policy
  • About
  • Search
  • Privacy Policy
© Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
Go to mobile version