Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manipulate URL inside ajax call?

I am trying to trigger an ajax call on change of a dropdown menu(at client_script.php). The ajax call will send some values to server_script.php and it will change a div section of the client_script.php. The problem is the server script is kept in a local directory such as blocks/latestgrades/server_script.php. When the ajax call is done the url becomes the address of the server_script.php prepended by

 http://localhost/umoodle 

Which is quite ok, because the server_script/php file location is such. But when I hover around the other pages, the onchange triggeres the ajax call which tries to find the server_script.php on that location but prepended by

http://localhost/umoodle/<something_i_dont_want_here>/

How to alter the url to cut that place I dont want and then do an ajax call with that?

like image 904
N. F. Avatar asked May 08 '13 19:05

N. F.


People also ask

How do I change the URL after AJAX success?

pushState("object or string", "Title", "/new-url"); See this post to Modify the URL without reloading the page for a basic how-to. Additional Note: The first parameter is the data we'll need if the state of the web page changes, for instance whenever someone presses the back or forwards button in their browser.

What is the URL parameter in AJAX?

The url parameter is a string containing the URL you want to reach with the Ajax call, while settings is an object literal containing the configuration for the Ajax request. In its first form, this function performs an Ajax request using the url parameter and the options specified in settings .

Can we use two URL in AJAX?

You can't call 2 url simultaneously. but you can call one after another. You can't put two URLs in an ajax call.

Can we redirect using AJAX?

Using $. post() to call a servlet using Ajax and then using the resulting HTML fragment to replace a div element in the user's current page. However, if the session times out, the server sends a redirect directive to send the user to the login page.


1 Answers

Make sure the ajax url is an absolute url (beginning with a forward slash) so that it is formed from the root instead of relative to the current page. For example: (url: '/umoodle')

like image 128
Josh Leeder Avatar answered Oct 01 '22 05:10

Josh Leeder