usually we create a url with parameters and values and send it via ajax to not loading page.

Is there a way to not send variables in the url BUT using hidden variables??

I have a problem in my website that doesn't permit me to send variable in url, so the ajax is not working anymore:

the problem is when i choose a language and the url become like this:
http//..../en/page -->here it is impossible to add variables to the url and success

is there a way to solve this issue??

hope i do get help :(

Best regards,
zanzo

Dani AI

Generated

The core issue is that "pretty" or rewritten URLs (for example a locale prefix like /en/...) remove the ability to append a query string directly. As pointed out, two robust choices are available: accept parameters in the path and translate them server‑side with rewrite rules, or send the parameters in the HTTP request body using POST from the AJAX call. The thread indicates a POST attempt still showed parameters in the URL; the notes below explain why that happens and how to fix it.

A minimal AJAX POST (request body, not URL) — jQuery example:

$.ajax({
  url: '/en/page',
  type: 'POST',
  data: { name: 'alice', age: 30 },
  success: function(resp){ /* handle */ }
});

Or using Fetch:

fetch('/en/page', {
  method: 'POST',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  body: new URLSearchParams({ name: 'alice', age: '30' })
});

Verification: use the browser DevTools Network tab. Confirm the Request Method is POST and look at Request Payload; if data appears as a query string on the URL line, something upstream is converting or appending it.

Common, easily tested causes when POST still looks like GET:

  • The code path actually calls a GET helper (e.g., $.get) or the AJAX options use the wrong property name (type vs method) so the library falls back to GET.
  • The client code explicitly builds and appends a query string (for example via url += '?' + $.param(data)).
  • The server responds with a redirect (3xx) that reissues a GET including query parameters.
  • JSONP is being used (JSONP requires GET).

If rewriting path segments is preferred, a simple Apache rule can map /en/name/age/page to internal query parameters:

RewriteEngine On
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/page$ /page.php?lang=$1&name=$2&age=$3 [L,QSA]

Security and best practices: POST hides values from the URL but not from logs or intermediaries — always use HTTPS and include CSRF protection for state‑changing requests. Additional reference material: jQuery.ajax docs (api.jquery.com/jQuery.ajax) and the Fetch guide (MDN Using Fetch); for rewriting, see the Apache mod_rewrite docs (httpd.apache.org/mod_rewrite).

Recommended Answers

All 8 Replies

> here it is impossible to add variables to the url and success

Why is it impossible?

What prevents you from creating a URL of the form ?

Anyways, if the operation involves POSTing data rather than GETting it, consider using POST requests rather than GET ones when making asynchronous calls.

Because, I'm using writing rule, i can't add "?name=somename&age=someage" to url!!
maybe if i add this parameters to the writing i can solve the problem??
/en/somename/someage/page!!

You have two options:
- Either come up with intelligent URL rewriting rules so that situation as mentioned above can be effortlessly handled. I am sure it can be, it just requires a bit of tact with regular expressions, that's all.
- Use the POST method when making asynchronous calls; this isn't as such recommended if you are trying to get some query results.

I think I will try the first option, as I'm using ajax and can't use post method!!

> I'm using ajax and can't use post method!!

Technically, you *can* use the POST method when using Ajax, there is nothing which prevents you from doing so; whether it pertains to your application/business is another question.

I tried to put "post" instead of "get" in ajax but still it sends the parameters in the url!! :S

Trial and error has little place in programming; get a good book or a solid online reference (MSDN or Mozilla tutorials) and learn more about Ajax.

Thanks for ur advices, I solved the bug ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.