Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:22:19+00:00 2026-05-23T10:22:19+00:00

I am running a server with Go programming language, and when I load the

  • 0

I am running a server with Go programming language, and when I load the server in the browser, the temp handler function is called and the getjson.html file is served by this temp Handler function. Now the screen shows a “Get Json Data” button. On clicking this button, I am not getting any results (as something should be displayed on the screen).

I checked the javascript console and there are no errors as such.
I am not able to figure out what the problem is, why isn’t there any output on the screen.

Contents of servejson.go :

package main

import (
    "http"
    "flag"
)

var path = flag.String("root", "/home/chinmay/work/json/getjson.html", "Set root directory, use absolute path")

func temp(w http.ResponseWriter, r *http.Request){
    w.Header().Set("Content-Type", "text/html")
    http.ServeFile(w,r,*path)
}

func main(){
    http.HandleFunc("/",temp)
    http.ListenAndServe(":8080", nil)
}

Contents of getjson.html :

package main

import (
    "http"
    "flag"
)

var path = flag.String("root", "/home/chinmay/work/json/getjson.html", "Set root directory, use absolute path")

func temp(w http.ResponseWriter, r *http.Request){
    w.Header().Set("Content-Type", "text/html")
    http.ServeFile(w,r,*path)
}

func main(){
    http.HandleFunc("/",temp)
    http.ListenAndServe(":8080", nil)
}

Contents of json_data.js:

{ 
  "firstName": "John",
  "lastName": "Doe",
  "age": 25
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:22:20+00:00Added an answer on May 23, 2026 at 10:22 am

    Yes, you can. Live example. Provided that json.txt is a resource next to the document in which this code is running, and (on some browsers) provided this is not running from a local file (e.g., a file:// URL rather than an http:// one; some browsers are okay with local files accessing other local files via ajax, others are not).

    A couple of notes:

    • In the

      $("div").append(field + " ");
      

      line, field will be the value of each property (e.g., “John”).

    • The order in which the properties are listed is completely undefined.

    So for this specific example, you’d probably be better off with

    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
        $.getJSON("json.txt",function(result){
          $("div").append(result.firstName + " " + result.lastName + " " + result.age);
        });
      });
    });
    </script>
    

    Live example


    Update: From your comments on another answer, it seems like you might be unclear on where and how the script code is running. The JavaScript script runs on the client’s browser. The path to use to reference json.txt is exactly like (say) the path to an image you want to show on a page. json.txt must be accessible via the web server, just like an image would need to be accessible via the web server. Think of json.txt as just another resource used by your web page, like any other. In terms of the path, and how you have to make json.txt available, the same rules apply. To be clear: Script running client-side in a web page cannot access a server-side file that can’t be retrieved by the browser.


    Update 2: You’ve posted more code, and it looks like you’ve made your server only serve the getjson.html file. Your server also has to serve the json.txt file, or the browser can’t access it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am about build a server on linux (I get to pick programming language)
I'm running VS2010, IIS7 w/ SQL Server 2008; programming a web application in C#.
I'm programming a very simple socket server following this sample code . The server
I saw Java -server in http://shootout.alioth.debian.org/ for programming language benchmark. I know that -server
Currently running Server 2003 but am looking at reinstalling in the near future due
Assuming I am not running server side scripting of any kind, how can I
Does anyone know how to monitor long-running server-side processes in GWT, other than polling
We've occasionally been getting problems whereby our long-running server processes (running on Windows Server
With VMWare Server running under Linux (Debain), I would like to have the following
If our server (running on a device) starts before a DHCP lease had been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.