retain "+" sign in string - ajax

I am creating a base64 string. There is also '+' sign in that string. I am sending it through ajax to the database. but ajax removes the + and replace it with white pace. How I can overcome this problem

How are you sending it to your server ?
You must urlEncode what's in the url, or use JSON.stringify for an object you send as json.
This means you must decode it on the server side but most server technologies handle this for you.

This is because you are not url encoding the base64 before sending it.
Run your base64 through javascript's escape() function before sending it.

Related

EXPRESS - Can't send "+" sign in POST

Simple question. I am sending POST request through AJAX:
`myreq=${JSON.stringify({info: "+"})}`
But all what I get in req.body.myreq is:
{"info":" "}
It's empty string or space... How I can send "+" sign??
The URL-encoded form of + is %2B. If you're using Javascript, perhaps use the encodeURI() function on your string, to encode it before sending it in a request. Remember that you'll need to use decodeURI() (or whatever language-specific equivalent) to decode it on the response side of the request, so that you can use it again.

JMeter, authenticity token has been encoded, how to decode

My script get an authenticity token from first page, then pass it to the second page I got this error when running the test:
{"errors":{"error:":["ActionController::InvalidAuthenticityToken"]}}
I checked the token variable, apparently the string such as /, = has been encoded into %2F and %3D etc..
On my second page's HTTP request window, I have NOT selected "encoded" for token variable defined in the "Send parameters with the request" section.
Apparently the problem is I did not asked for encoded variable, JMeter just encode it. Is it a known bug or I should do something to decode it or is there a work around on this issue?
Did you pass token in POST data?
I'v faced the same problem and just pass body data as work around, to do it you need:
Select you HTTP sampler
Switch from "Parameter" to "Body Data" tab (you have to delete all parameters to do it)
Write body data (variable substitution works)
Body data example:
username=Some_name&token=AbRaCaDaBrA
NB, if something need to be encoded, you'll have to do it manually.

Do I need to send the data in $.ajax as json?

I have an $.ajax request that's sending the data in a serialize() and gets a json array in return. It works perfectly without any issues on Chrome develop's tools and Firefox's firebug. My question is, do I HAVE to send the data(user inputs) as json? I need json for the response but not for the request.
No, you send the data however you like but keep in mind how you send it will affect how you can retrieve it.
Also you aren't sending JSON in your request as .serialize() does not return JSON it returns a text string in standard URL-encoded notation.
No, you don't need to send it as JSON. You can send it in any other format, but your receiver will need to know how to interpret it. Usually people use JSON or XML since your receiver can easily parse these types of data.
You'll need to set the content-type, then you can tell the receiver how to process this content-type.

Should a JSON-P callback function accept a string?

I'm calling a REST API somebody else created. It supports JSONP to facilitate cross domain access.
The response I get back from the service looks like:
mycallback('{"token": "123456789"}');
Notice the single quotes wrapping the JSON data; Passing it as a string rather than a raw object. JQuery can handle this, but other libraries seem to expect a raw object instead.
mycallback({"token": "123456789"});
The raw object parameter makes more sense to me since it avoids the need to parse the JSON data, but I want to know for sure before asking the maintainer of the API to make the adjustment:
Which is most correct?
Passing a javascript literal (second) as shown here is more correct as it avoids deserializing the string back to a javascript object.
Passing a string is obviously a bad thing - you have two choices (#1 is preferred):
Ask the developer of the JSONP service to send proper JSONp instead of a string
Make your callback function smart so it uses something like payload = JSON.parse(payload); in case payload is a string.

ajax search suggest escape encoding

if encoding using escape(data) in javascript, how to decode it in server side?
I use ajax to post encoding data with escape javascript function, how can I decode it at the server side with classic asp
If you are passing arguments in URL (get method), do not use encode().. use encodeURI() function instead. Now, the data (I mean the parameters you pass) comes decoded automatically.

Resources