When processing UTF-8, REST only acknowledges English characters and ignores any other characters

When sending an AJAX request in UTF8 to a server that uses REST, any part that contains non-English characters is disregarded.

I am working with Java on the server side with REST, and the client sends AJAX requests in UTF8 that may include Hebrew words.

Here is an example of the AJAX request:

var clientNumber  = '12344432432';
var userID = '321321321';
var someHebrewWord = ...;
var someEnglishWord  = ....;

var servletUrl = '/Management/services/manager/' + clientNumber + '/' + userID + '/' + someEnglishWord + '/' someHebrewWord;
alert('Sending this :' + servletUrl);
$.ajax({ 
    url: servletUrl,
    type: 'POST',
    cache: false, 
    data: { }, 
    success: function(data){
        alert('Return value is:' + data);
        window.location = "./replyPage.html";
    }
    , error: function(jqXHR, textStatus, err){
        alert('text status '+textStatus+', err '+err + " " + JSON.stringify(jqXHR));
    }
});

On the server side, I implement REST as follows:

@Produces({ "application/json" })
@Path("/manager")
public class Management {


    @POST
    @Path("{clientNumber}/{userID}/{someEnglishWord}/{someHebrewWord}")
    @Produces("application/json")
    public boolean insert(@PathParam("clientNumber") String clientNumber, @PathParam("userID") String userID,
                              @PathParam("someEnglishWord") String someEnglishWord, @PathParam("someHebrewWord") String someHebrewWord) 
    {
        // perform some operation 
    }


    @POST
    @Path("{clientNumber}/{userID}/{someEnglishWord}")
    @Produces("application/json")
    public boolean updateSomething(@PathParam("clientNumber") String clientNumber, @PathParam("userID") String userID , @PathParam("someEnglishWord") String someEnglishWord)

    {
        // perform some other operation
    }   



    // more code 

}

Although I am sending 4 fields in the AJAX request, the updateSomething() method is being invoked instead of insert(). Why is this happening and how can it be fixed?

Any help is greatly appreciated.

Answer №1

There are limitations on the characters allowed in a URL. To address this, it is necessary to encode the URL using the encodeURIComponent method.

Another effective approach could be to store the parameters in a data variable and utilize @FormParam instead of @PathParam.

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

What is the method to prevent the label from closing in the MUI 5 datepicker?

Is there a method to prevent the Material 5 Datepicker from closing when there's a label but no value? Current Scenario: Current Desired Outcome: Expected Sample Code: <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker lab ...

Using ASP.NET Server Controls to Toggle Textbox Visibility Based on Dropdown Selection

What is the optimal method for displaying or hiding a textbox or an entire div section based on a user's selection from a dropdown menu? I am uncertain if this can be achieved with server controls, so would it require using standard client-side HTML c ...

Are there any available resources in Node.js or REST API for establishing new user accounts in Office 365?

I recently bought the Office 365 essentials plan and have been able to set up an admin account. However, I am looking to streamline the process of adding new users under this account by utilizing a Node.js or REST API. Despite conducting thorough researc ...

It's next to impossible to secure expedited work on an ongoing project using Vercel

Yesterday, I successfully deployed an application on Vercel using only ReactJS. Today, I made the decision to develop an API for my application, To clarify, I have a folder housing the React app, and within that, I created a directory named "api" followi ...

Ways to extract information from PayFast

One issue I'm facing with my online store is that although PayFast does call my notify_url, it appears that no data is being posted. Below are the codes I've been using: Code for purchasing: <button id="cCart" type="submit" class="bt ...

The Ajax deletion request yields a 200 response code; however, it triggers an error instead of the

Hi, I am struggling to identify where I went wrong with the delete function. The function itself works fine, but I keep getting an error message even though the JSON response shows success. $(document).on('click', '.remove-btn', functio ...

Transferring data from a table to another window

Currently, I am retrieving values from a database and displaying them in a table. I would like to add a button to each row that will allow users to view more details about that specific row. At the moment, only ThesisID, AuthorID, and Title are visible. ...

Trouble with PUT request for updating user password using Express.js with mongoose

I've encountered a puzzling issue while working on my Express.js application. Specifically, I have created an endpoint for updating a user's password. Surprisingly, the endpoint functions flawlessly with a POST request, but fails to work when swi ...

Launching a centered pop-up window to display a submitted form message

I am attempting to create a page that displays a confirmation message in a center-aligned pop-up window after the user submits a form. I have managed to open the page in a pop-up window, but I am struggling to center the window using my current code (I pre ...

Is there a way to manipulate a website's HTML on my local machine using code?

I am currently working on a project to create a program that can scan through a website and censor inappropriate language. While I have been able to manually edit the text using Chrome Dev tools, I am unsure of how to automate this process with code. I ha ...

Looking to display or conceal a text box with a date picker based on the selection of a specific value from a drop-down menu

I have a dropdown with two options: Indian and Others. When I select Others, I want to display three textboxes - two with date pickers and one with a simple text input field. I have tried writing the following HTML code but I am unable to get the date pick ...

Change a PNG file into a three.js plane by converting it into height

I have a visualization challenge using three.js. I am working with an image linked here: https://i.sstatic.net/EzfcS.png. I am using a plane geometry and I aim to adjust the height of the plane according to this other image: https://i.sstatic.net/hMj91.png ...

Discover how Ajax pulls information from a Ruby on Rails controller

I have been teaching myself how to work on projects, but I am not very familiar with ajax or Ruby on Rails. Currently, I am trying to use ajax to retrieve data from a controller. However, I am unsure about how to specify the URL in my code: $.ajax({ t ...

A guide to transferring modules between component files in JavaScript

My query pertains to the handling of imports in web pages. When a file is imported into another, do the declarations and imports from the imported file become available in the file where it is being imported? A suggestion was made for me to import a compo ...

What is the best approach for managing client-side routes when a page refresh displays the backend Rails route instead?

After deploying my SPA to Render, I encountered an issue. My application comprises a React frontend with Redux and a Rails backend. When the app initializes, it correctly displays the frontend route in the browser. Subsequent navigation without refreshing ...

Redirect to URL using Ajax upon successful completion

I'm facing an issue with my function as it doesn't redirect after a successful operation. I'm not sure why the redirection is not happening consistently. Sometimes, adding ...href after e.preventDefault(); seems to work. $('#nadwozie&a ...

Changing the link color within a repeater in ASP .NET when it is clicked

The given code snippet is being executed on an iPhone 4, causing some CSS elements like Hover to not function as expected. <asp:Repeater ID="rpt" runat="server"> <HeaderTemplate> <div class="table withshadow"> </Header ...

Tips for injecting scripts into the head tag after an Angular component has been loaded

Currently, I am facing an issue with a script tag containing a Skype web control CDN. The script has been placed in the head section of my index.html file, but it is being called before the component that needs it has finished loading. Does anyone have a ...

What is the reason for requiring this to be passed as an Array instead of a String?

I'm currently learning node.js through a tutorial in a book titled Node Web Developments. Issue: I am struggling with understanding why an array [] is being passed as the 3rd argument from mult-node.js to the required function htutil.page(), instead ...

Error encountered due to incompatible date format in SimpleDateFormat

How can I extract milliseconds from a date without encountering an exception? I'm receiving the error: java.text.ParseException: Unparseable date: "Thu Jul 25 10:56:29 GMT+02:00 2019" This is the approach I've taken: Firstly, I retrieved the ...