L
L
Ler Den2018-03-12 14:18:20
JavaScript
Ler Den, 2018-03-12 14:18:20

How to encode the & character in a GET request?

From the frontend I send data with a GET request: name, email. On the backend (php, Laravel) I read this data. The problem appears when the name contains the character '&', then the name is cut off at that. How can I send parameters so that there are no such problems? The post does not work - a csrf token error pops up, which is not clear how it came from there and how to fix it (perhaps due to the fact that the domain is not ssl?). In general, in GET priority, because The data is not secret and is easier to process. Line example:
'page?name=G&Company&[email protected]'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Makarov, 2018-03-12
@givemoneybiatch

To prevent a csrf error from appearing in a post, send a header with a token with the request, like this:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]'). attr('content')
}
});
Provided, of course, that the appropriate meta tag is included in the header of your html.

S
SagePtr, 2018-03-12
@SagePtr

URL encode them. In PHP - urlencode function, in JS - encodeURIComponent

F
frees2, 2018-03-12
@frees2

In principle, I'm sorry, maybe not quite on the topic, if there is ?name=, you can send requests without '&', using your character, you did it, but parse it or use it differently when receiving.
?name= You can pass the time in a string, and then, for example, encrypt or not encrypt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question