What is the process for setting %20 to represent a space in URL parameters?

I am currently working on developing an android application that involves sending data to the server side using GPRS and SMS (via an SMS gateway). The challenge I am facing is with formatting the data before sending it to the SMS gateway. The format provided includes white spaces between the data elements. However, when these white spaces are URL encoded, they appear as "+" symbols. I would prefer to encode the space as "%20" instead of "+", as URLs do not fully support the use of "+". How can I achieve this? Your help is greatly appreciated. Thank you in advance.

Here is the source code:


function AttForm()
{
var att=$('#attnce').val();
var uname=window.localStorage.getItem('uname');
if(att==0){
alert("Select Attendance");
return false;
}

var message="MRCC";
message += " "+"VIPATT";
message += " "+uname;
message += " "+att;

var networkState = navigator.network.connection.type;

var states = {};
states[Connection.UNKNOWN]  = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI]     = 'WiFi connection';
states[Connection.CELL_2G]  = 'Cell 2G connection';
states[Connection.CELL_3G]  = 'Cell 3G connection';
states[Connection.CELL_4G]  = 'Cell 4G connection';
states[Connection.NONE]     = 'No network connection';

if(states[networkState]==states[Connection.NONE]){
window.plugins.sms.send(09192939495,message,function(){ 
alert('Message sent successfully');  
},
function (e) {
alert(e);
});
}
else{           
$.ajax({
url:'http://aaa.com/test/webservice.php',
type:'POST',
data:{type:'VIPATT',message:message},
dataType:'jsonp',
jsonp:'callback',
success:successData,
error:function(){
alert("error")
}
});
function successData(data){
var response=data.message;
alert(response);
$('#att').hide();
$('#main_menu').delay(500).fadeIn(1000)
}
}

}

The URL generated looks like this:

http://aaa.com/test/webservice.php?callback=jQuery16006898061116226017_1343803442450&type=VIPATT&message=MRCC+VIPATT+RSA+2&_=1343803455743:1

In the above URL, you can notice the presence of the "+" symbol between the attributes. However, I aim to replace the "+" with "%20". Any suggestions on how to achieve this?

Answer №1

To properly encode a URL, it is suggested to use a URL encoding function. Though I have not personally tried it myself, I came across an informative article that could offer assistance - check it out here

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

Experiencing the AngularJS [$injector:modulerr] error message despite having flawless code

Despite having code that appears to be correct, I am consistently receiving an [$injector:modulerr] error when working with AngularJS. Check out the updated Fiddle here. I can't seem to figure out what the issue is. Could I be missing something obvi ...

inserting a dynamic variable into a JSON string

My goal is to create a javascript object, var systemName = {"system" : varA}; However, I want the object to be structured like `{"system" :"varA"} where varA contains the variable value but is enclosed in double quotes. I attempted {"system" : "'+ ...

Challenges with line height in IE when adjusting font size in textarea

I'm facing an issue with adjusting the font size in a textarea using JavaScript. While it works perfectly in Firefox, there are some problems in IE. Specifically, the line-height does not change accordingly. This results in gaps between lines when the ...

An issue with displaying images has been identified within Next.js, resulting in an error message related to the hostname

Encountering an error when using next js Image next.config.js: module.exports = { images: { domains: ['localhost'], }, }; Error image: https://i.stack.imgur.com/RvsdH.png I am struggling to understand how to correctly set up the image ...

How to Use an Object Created from a Different Class in TypeScript

Scenario In the development process, I am using an auth.service.ts. This service is responsible for fetching user information from the database upon login. The retrieved data is then used to create a new user object. Here is a snippet of the code: user: ...

Master the art of automatically formatting incorrect JSON using code in your Flutter project

I am currently facing an issue while trying to parse a json response. The problem lies in the presence of a trailing comma at the end of the response, causing errors during decoding. Is there a way to automatically format it from the code and remove the co ...

Achieve the hidden div scroll effect in React by initially hiding the div and then allowing

I am currently working on a web chat application using next.js. One of the features is an emoji picker button that, when clicked, displays a menu of emojis. The issue I am facing is that in order for the user to see the emoji menu, they have to scroll down ...

The backbone module is experiencing formatting issues

I'm new to learning backbone.js. I've created the example below, but unfortunately, it's not functioning properly. Can someone please help me understand why? The goal is to simply display the name within my div element. (function($) { ...

Ensuring the existence of a MySQL database prior to executing a Node.js application

I am currently working on a Node.js/Express application that communicates with a MySQL server using Sequelize. I want to make sure that a particular database is created before the app starts running when using npm start. I think I need to create a one-ti ...

Discovering a specific JSON object member by its corresponding string value

Let's consider a JSON file with information about books stored in it: { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "autho ...

Customize the color of the label and underline in a Reactjs material-ui TextField when the field input

https://i.stack.imgur.com/oJ2ah.png <TextField id="standard-full-width" label="Password" style={{ margin: 8 }} fullWidth margin="normal" placeholder="*******" /> Struggling to understand how to modify the color of the label ...

What is the best way to send props from page.js to layout.js in the Next.js app directory?

Is there a way to effectively pass props to layouts in Next.js 13? Can we optimize the approach? Here's an example: // layout.js export default Layout({children}) { return ( <> {/* Display different `text` based on the page.js being ...

Incorporating lodash into Angularjs for enhanced functionality

After stumbling upon an app online that utilizes AngularJS with Lodash, I noticed a simple way in which Lodash is incorporated. By including the following line in the body (after angular has been included): <script src='vendor/lodash/3.3.1/lodash. ...

Break up JSON into distinct JSON files based on node value using Python

Looking to utilize Python to split a JSON file into separate files based on the "transactionTypeName" found within the transactions.details. Each file should include all details starting from careperson to username. Here is an example of the JSON file afte ...

Errors with pointer events occurring within nested iframes on Chromium 78

At first glance, it seems like a bug specific to Chromium. I have already reported this issue in a bug report. Since progress is slow on that front, I am posting a question here primarily to see if anyone else has encountered similar or related issues and ...

Issue with Ajax/Json: "An object of type triggers a circular reference error when attempting to retrieve a list."

Recently, I encountered an issue with my server-side method that is triggered through JSON/Ajax. The method itself functions flawlessly and sends back a list as expected. However, I seem to have made an error in my JavaScript code, leading to the following ...

Issues with Unity JSON API

I am currently facing a challenge as I attempt to save an n x m field array as JSON in a text file within Unity. Due to the limitation of Unity not supporting array types for top-level JSON deserialization, I have created a custom class structure like this ...

Can Next.js 13 support the usage of axios?

Despite trying to implement the SSG operation with the fetch option {cache: 'force-cache'}, I consistently received the same data even when the mock server's data changed. I found that using the fetch option {cache: 'no-store'} do ...

Error Message: Undefined Constructor for Firebase Google Authentication

Hey there! I've been working on integrating Firebase google authentication into my project. Unfortunately, I encountered an error while testing it out. Here's the error message that appeared in the console: Uncaught (in promise) TypeError: Cannot ...

In JAX-RS, the attributes of a POJO are being returned as an Array in JSON format

Running a java web maven project with JAX-RS using resteasy version 2.2.1.GA implementation. All JAX-RS resources on the project produce and consume application/json. The issue arises when trying to return a single POJO or an array of it, as only the value ...