JSON does not send information to the specified web address

Attempting to send some data to the following URL: "

    $(function() {
             var frm = $(document.myform);
             var data = "?lm_po_id=154668&authentication=ThisisAuth&description=ThisIsDesc";//JSON.stringify(frm.serializeArray());

//var data = JSON.stringify(frm.serializeArray()); // Also attempted this

         alert(data + "I am ready to POST this:\n\n" + data);
         $.postJSON = function (url, data, callback) {
                $.ajax({
                    'url': frm.attr("action"),
                    'type': 'post',
                    'processData': false,
                    'data': JSON.stringify(data),
                    contentType: 'application/json',
                    success: function (data) { callback(JSON.parse(data)); },
                });
            };
     });

The function is called correctly, but all parameters appear as null values when checked in debug mode. Can someone please assist me in identifying what mistake I am making? Here is my HTML form

<form action="http://192.168.0.124:8080/Ilex-WS/service/ilexmobile/poImageUpload" name="myform" method="post" enctype="multipart/form-data">
    <input type="text" value="158664" name="lm_po_id" /><br />
    <input type="text" value="AuthCodeMD5" name="authentication" /><br />
    <input type="text" value="584" name="imagenumber" /><br />
    <input type="text" value="ImgName.png" name="name" /><br />
    <input type="text" value="This is desc" name="description" /><br />
    <input type="file" value=""  name="uploadedimage" /><br /> 
    <input type="button" value="Submit" onclick="javascript:document.myform.submit()"/><br />
</form>

Appreciate your help in advance....

Answer №1

The primary purpose of your JavaScript code is to display an alert message.

There is no event handler attached to the form's submit action, and even if it was, it wouldn't trigger because you are using form.submit() instead of a submit button. This results in submitting form encoded data rather than JSON encoded data.

You define a function within $.postJSON, but it is never invoked, and it contains a local variable named data which overrides another variable declaration var data = "?lm_po.... Furthermore, passing this value through JSON.stringify doesn't serve any logical purpose.

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

Posting Json data to Influxdb using REST API

How can I upload a JSON using Rest Api on Influx? I noticed that when reading data from Influx using Rest+query, it comes in JSON format. However, now they are saying that JSON is deprecated for uploading and we must use binary format instead. Is this rea ...

Updating View in Angular 2 ngClass Issue

I'm encountering some challenges with updating my view using ngClass despite the back end updating correctly. Below is my controller: @Component({ selector: 'show-hide-table', template: ' <table> <thead> ...

Mastering the utilization of the Data object in VueJS with Decorators can be tricky. One common error message you might encounter is, "Class method 'data' expected 'this' to be used."

Error > The class method 'data' should use 'this' but it is not. I encountered this issue and believed I fixed it as shown below: TypeScript Unexpected token, A constructor, method, accessor or property was expected <script lang ...

What is the best way to send props from a child component to its parent in a React

I'm a beginner in React and I'm attempting to develop a "CV-Generator" similar to the one shown here. In this application, whenever a user inputs data in any of the input fields, it is automatically displayed in the render preview on the right si ...

Technique for identifying a sequence within a longer numerical series

As I ponder this puzzle for what seems like an eternity, I humbly turn to you for a possible solution. A lengthy number resembling this one: 122111312121142113121 It is crucial to note that no numbers exceed four or fall below one. Now my quest is to une ...

Discover the smallest and largest values within the multi-layered object

My JavaScript object is deeply nested with an infinite number of children, each containing a value. var object = { value: 1, children: { value: 10, children:{ value: 2, children: {...} } } } I've tried ...

Is there a way to streamline the import process for material-ui components?

Is there a shortcut to condense all these imports into one line? As a newcomer to react, I've noticed that every component must be individually imported, especially when it comes to CSS components. Could you provide me with a suggestion on how to st ...

Next.js fails to properly render external links when utilizing the Link component

It was quite surprising to discover that a basic Link component doesn't function as expected in Next.js when attempting to use it with an external URL and HTML Button tag within. Here is my attempt at solving this issue: Attempt 1: <Link href="h ...

Avoid reactivating focus when dismissing a pop-up menu triggered by hovering over it

I am currently utilizing @material-ui in conjunction with React. I have encountered the following issue: In my setup, there is an input component accompanied by a popup menu that triggers on mouseover. Whenever the menu pops up, the focus shifts away from ...

Displaying an image within a textarea using JS and CSS

Could someone help me create a form with textareas that have small images on them? I want clicking on the image to call a function fx(). Can anyone code this for me using JavaScript/jQuery/CSS? In the image below, clicking on "GO" will call Fx() I attemp ...

Dealing with errors in Next.js when using axios in Express

Currently, I am working on implementing the login feature for my application using an asynchronous call to my API. The issue I am facing is that despite express throwing an error, the .then() function is still executing with the error instead of the actual ...

Clear Vuex state upon page refresh

In my mutation, I am updating the state as follows: try { const response = await axios.put('http://localhost:3000/api/mobile/v3/expense/vouchers/form_refresh', sendForm, { headers: { Accept: 'application/json', 'C ...

Step-by-step guide on displaying a fresh page within a JavaScript code

I've been working with XHTML, JSF, and JavaScript to develop a form that validates user input in selected fields when a button is clicked. The goal is to redirect the user to a different page called homepage.xhtml after successful validation. However, ...

What is the reason behind the default disabling of bootstrap multiselect options?

Just diving into the world of bootstrap and I'm puzzled as to why my simple multiselect options aren't responding when clicked. UPDATE The first multiselect option on the test-site linked below is the one giving me trouble. I've tried it o ...

"Before the click even happens, the jquery click event is already

As I was developing a small todo app, I ran into an issue where the alert message seemed to pop up before the click event was triggered. It almost seems like the event is not registered properly. Can someone explain why this is happening? (function() { ...

Struggling to loop through a child in Firebase real-time database?

I'm struggling to retrieve a nested child from my database with the following structure https://i.stack.imgur.com/ZDs38.png I am attempting to get the URI from the Gallery object. When I log in, I can see this in the console https://i.stack.imgur.c ...

No data being displayed or returned from API when using async await

My Ionic 6 + Angular 14 application is currently facing an issue with displaying data retrieved from an API... I have implemented a service to fetch the data from the API and then called this service in the component. The app compiles without any errors a ...

Error: JSON requires string indices to be integers

I need help filtering JSON data from a webhook. Here is the code I am working with: headers = { 'client-id': 'my twitch client id', 'Authorization': 'my twitch oauth key', } params = ( ('query' ...

Forwarding information and transferring data from a Node server to ReactUIApplicationDelegate

I am currently working on a NodeJS server using Express and React on the front-end. I am trying to figure out how to send data from the server to the front-end without initiating a call directly from the front-end. The usual solutions involve a request fro ...

What is preventing the addition of links to the navigation bar when using a sticky navigation bar?

Currently, I am in the process of developing a blog website using Django. One of the features I have successfully implemented is a sticky navigation bar. However, I am facing a challenge with adding links to the menu on the navigation bar due to existing ...