Interpret the JSON reply

Could someone please explain why my function B() is not responding?

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
    var sessionID=null ;
    function A() {
        $.getJSON('http://url.php?id=login&email='+document.getElementById("txtemail").value+'&password='+document.getElementById("txtpassword").value,
                function (data) {sessionID = data.session_id;
                    alert(data.status);
                    alert(data.msg);
                    alert(data.user_id);
                    alert(sessionID);
                });
    }
    function B() {
        $.getJSON('http://url.php?id=chat_init&sess_d='+sessionID+'&user_id='+document.getElementById("user_id").value+    '&to_id='+document.getElementById("to_id").value,
                function (data) {
                    alert(data.status);
                    alert(data.msg);alert(data.room_id);
                });
    }
</script>
</head>
<body>
Username :  <input type="text" id="txtemail" />
<br/><br/>
Password :  <input type="password" id="txtpassword"/><br/>
<input type="button" value="Login" onclick="A()" /><br />
My id is :  <input type="text" id="user_id" /> <br /><br />
To ID is :  <input type="text" id="to_id"   /><br /><br />
<textarea rows="10" cols="25">
</textarea><br /><br />
<textarea rows="2" cols="18"> </textarea>
<input type="button" value="Initialize chat"  onClick="B()">

</body>
</html>

This is the snippet of code I am referencing.

Answer ā„–1

It is recommended to use a relative path instead of the full URL when utilizing this function.

For example, you should change http://url.php to youscript.php. Additionally, consider using the ajax-function instead of getJSON for personal preference.

Answer ā„–2

'http://url.php' does not meet the requirements of a valid URL.

For proper functionality, use either a relative path ("url.php"), an absolute path ("/url.php"), or a fully qualified path ("http://www.example.com/url.php").

LATEST UPDATE

http://url.php cannot be used on a public website.

When a browser tries to access url.php, it will attempt and fail to resolve it to an IP address.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the height of a div vertically in Angular 2+

Recently, I started using angular2 and I've been attempting to create a vertically resizable div without success. I have experimented with a directive for this purpose. Below is the code for my directive: import { Directive, HostListener, ElementRef ...

Modifying the text within the label of a multibarchart in nvd3.js

After analyzing the multibarchart in nvd3.js, I have discovered that it requires a specific JSON format as input. [ { "key": "abcd", "values": [ { "x": 1221578789000, "y": 40 }, { "x": 1222578789000, ...

Discovering the culprit causing a freeze on your page: Uncovering the tool or technique to identify the problematic

What is the best tool to identify resource-heavy or infinite loop JavaScript/jQuery scripts? I am currently experiencing issues with a specific template: When I open this page on Firefox 46.0.1, it freezes after a few minutes. I am having trouble pinpoin ...

Guide to extracting data from a JSON object in node.js

I'm having trouble with the following code. How can I retrieve TripNo from a JSON object? model.Gps.find({EmpName:empName}, function(e,o){ var jsonvar = JSON.stringify(o); console.log(jsonvar.TripNo); }); Here is the schema: var ...

Utilizing JSON data for efficient React component rendering

As a newcomer to React, I am currently in the process of constructing a dashboard that showcases data from three different sensors. The information regarding these sensors is stored in a single JSON file where each sensor has its own ID and name. This JSON ...

Is there a way to transform the XML output from Roku TV's API into JSON format?

I've been working on developing an application that interacts with the Roku TV ECP API commands. One specific call I'm attempting to make retrieves a list of all installed channels and returns it in XML format. However, every time I make this API ...

When utilizing Javascript's Array.push method, a nested array is generated that is inaccessible using the index

I have reviewed several articles discussing the issue of asynchronous calls returning undefined. Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference Get data from fs.readFile However, none of these articles ...

In ReactJs, what is the best way to load a new component when a button is clicked?

In ReactJs, I have developed a main component known as MainPage using Material-UI. import React from 'react'; import Grid from '@material-ui/core/Grid'; import Button from '@material-ui/core/Button'; import CssBaseline from & ...

Unable to close Bootstrap sidebar menu on mobile devices

I implemented a sidebar menu for mobile that opens when you click on the hamburger icon, with a dark overlay covering the body. The issue I encountered is that on mobile devices, the visibility of the menu does not change when clicked outside of it. It wor ...

Send JSON data to Riak using the `curl` command

I am working with a JSON object: { title: "Some title", author: "Name", text: "This is text..." } My goal is to save this JSON data to my Riak database using the curl command as follows: curl -v -X PUT http://192.168.56.12:10018/riak/news/news1 ...

Eliminating 'related' elements with jQuery

I am facing an issue with deleting items in a list. The list contains two types of products, product-x and product-y. Whenever I delete one type of product, I want the equivalent product of the other type to also be deleted. I have tried different approac ...

Retrieve a zip file using React and Node from a RESTful API

I have an application built with React and Node where I have a table that includes a download button. Clicking the download button triggers a request to my Node app, which in turn should call a REST API to download a zip file directly into the browser. In ...

Angular's implementing Controller as an ES6 Class: "The ***Controller argument is invalid; it should be a function but is undefined."

Struggling to create a simple Angular todo application using ES6. Despite the controller being registered correctly, I keep encountering an error related to the title when navigating to the associated state. *Note: App.js referenced in index is the Babel ...

Discovering distinct colors for this loading dots script

Looking for assistance with a 10 loading dots animation script. I'm trying to customize the color of each dot individually, but when I create separate divs for each dot and control their colors in CSS, it causes issues with the animation. If anyone ...

Using Ajax (Jquery) to send data to a PHP script

Currently, I am working on an application where users can click a checkmark to complete a task. When this action is taken, a popup window appears (created using bootstrap), prompting the user to enter their hours worked on the task. After entering the hour ...

Troubleshooting Issue: XMLHttpRequest Incompatibility with Internet Explorer

I'm having an issue with the script below. It works fine on Firefox and Chrome but doesn't seem to work on IE. I've tried various solutions, including lowering the security settings on my browser, but it still won't work. function se ...

Tips on transforming json to csv format

Can someone help me convert the JSON output below to a CSV format? {u'status': u'success', u'data': {u'candles': [[u'2020-05-15T09:15:00+0530', 9163.95, 9165.05, 9090.55, 9115.9, 440475, 7516350], [u' ...

Adjust CardMedia Images to match their content in the new MUI 5 version

Iā€™m looking to have my images fully fill the CardMedia component. However, because they are of varying sizes, some end up being cropped like this: https://i.stack.imgur.com/JHIrT.png Additionally, when resizing the images, some get cut off as well: ht ...

When utilizing an 'imported' asynchronous function, make sure to clean up the useEffect

Please do not mistake this for a duplicate. Despite my thorough search on various blogs and sources, I have yet to find a solution. My primary question is 'how can I address the error of react state change in unmounted component, and also cancel an a ...

The method of altering a menu link in WordPress using jQuery varies according to whether the user is logged in or not

I need to update the last link on my menu. When a user is logged in, it should display a profile link; otherwise, it should show a sign-up link. ...