Hi, I want to access a web service and get the response in json using javascript.
The web services can respond in json and gives me a table of records with a specific campus.
I input the campus code in the text box and create the url.
Now, I want to get the response in json and I'm really stuck.
Can anybody give me some clues please?

<FORM NAME="myform" ACTION="" METHOD="GET">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="loadurl(this.form)">

function getData(form) {
var baseUrl = "https://studentwebservices/rest/location/campus/";
var campus = form.inputbox.value;
var url = baseUrl + campus; 

// Code to be added


From the information search process:
I know I have to change the HTTP Header accept and use application/json
and probably use JSONRequest.get()

This is my very first post on a forum.

Edited by Dani: Formatting fixed

5 Years
Discussion Span
Last Post by spatlola0422

Here is sample json example, I hope you get something from it.

<h2>Create Object from JSON String</h3>
First Name: <span id="fname"></span><br /> 
Last Name: <span id="lname"></span><br /> 
<script type="text/javascript">
var txt = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"adSmith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';

obj = JSON.parse(txt);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.