Ajax not sending request to php when url directory changes


Zuckerberg

Now, this query is really not being asked and I ended up dropping the service because I couldn't find a sensible answer to my query.
On my apache2 server, I've enabled rewrite rules in the .htaccess file in the root directory to keep pointing everything except directories and files to a certain php file at all times, this works fine, but when The ajax script fails when the url changes directory.

This is the php script [testing...]

<?php

//now if run the test using the root directory, i get clear response,
//but as i have told u, i have enabled apache2 module and added rewrite rules to .htaccess,
//meaning that no matter hat the url is, the url will keep pointing to the same file but the problem
// is that the ajax script does not fire p the request / send.
//i dont jnow what i am doing wrong...

if(isset($_GET['test_changes'])){
    echo 'the request has now reached the server';
    exit;
}

?>

this is the ajax script

<script>

    //my ajax script is like this
    //the url seen below is in the root directory.
    //So briefly,how would i keep this url pointing to the same php file even if the directory changes

    $.ajax({

        url:'test.php?test_changes=123456789',
        cache:false,
        async:true,
        method:'GET',
        success:function(response){
            console.log(response)
        },
        error:function(error){
            console.log(error)
        }

    })
</script>
Dennis Lake

Please use absolute urls to get the job done...see code below

<?php


//it would still received the request
if(isset($_GET['test_changes'])){
    echo 'the request has now reached the server';
    exit;
}

?>






<script>
    //i had a little trouble thinking this through but i got it working after sometime
    //Now You need you ajax script url to be absolute to achieve something like that
    //by prepending a forward slash character to your URL

    $.ajax({
        url:'/test.php?test_changes=123456789',
        cache:false,
        async:true,
        method:'GET',
        success:function(response){
            console.log(response)
        },
        error:function(error){
            console.log(error)
        }
    })
</script>

Related


Ajax not sending request to php when url directory changes

Zuckerberg Now, this query is really not being asked and I ended up dropping the service because I couldn't find a sensible answer to my query. On my apache2 server, I have enabled rewrite rules in the .htaccess file in the root directory to always keep everyt

Ajax not sending request to php when url directory changes

Zuckerberg Now, this query is really not being asked and I ended up dropping the service because I couldn't find a sensible answer to my query. On my apache2 server, I have enabled rewrite rules in the .htaccess file in the root directory to always keep everyt

Ajax not sending request to php when url directory changes

Zuckerberg Now, this query is really not being asked and I ended up dropping the service because I couldn't find a sensible answer to my query. On my apache2 server, I have enabled rewrite rules in the .htaccess file in the root directory to always keep everyt

Ajax not sending request to php when url directory changes

Zuckerberg Now, this query is really not being asked and I ended up dropping the service because I couldn't find a sensible answer to my query. On my apache2 server, I have enabled rewrite rules in the .htaccess file in the root directory to always keep everyt

Ajax not sending request to php when url directory changes

Zuckerberg Now, this query is really not being asked and I ended up dropping the service because I couldn't find a sensible answer to my query. On my apache2 server, I have enabled rewrite rules in the .htaccess file in the root directory to always keep everyt

PHP returns no data when sending ajax request

beans, lentils When I send an ajax post request to my getMessages.php file it returns nothing. I've tried manually setting the array values and printing them in the console and that seems to work. get message.php <?php require_once "mysqli.php"; $data = arra

No data response when sending ajax request to php

Markop I want to send a json data to my php but when i access it to my php there is no response. this is my ajax request var project = {project:"A"}; var dataPost = JSON.stringify(project); $.ajax({ url: 'fetchDate.php', data: {myData: da

No data response when sending ajax request to php

Markop I want to send a json data to my php but when i access it to my php there is no response. this is my ajax request var project = {project:"A"}; var dataPost = JSON.stringify(project); $.ajax({ url: 'fetchDate.php', data: {myData: da

PHP returns no data when sending ajax request

beans, lentils When I send an ajax post request to my getMessages.php file it returns nothing. I've tried manually setting the array values and printing them in the console and that seems to work. get message.php <?php require_once "mysqli.php"; $data = arra

PHP cannot read $_GET parameter when sending AJAX request

Ed91gg I've been struggling with this since a few months and finally got to the point where I need to fix it in my project. The problem is, I am sending an ajax request to a php file where I need to read the current $_GET['user_id'] value to insert the query.

PHP cannot read $_GET parameter when sending AJAX request

Ed91gg I've been struggling with this since a few months and finally got to the point where I need to fix it in my project. The problem is, I am sending an ajax request to a php file where I need to read the current $_GET['user_id'] value to insert the query.

Ajax not sending var to url php

Engin Erdogan I'm trying to send a variable to the server, but the url doesn't go to the php file. Is it because I am not using the submit button? Here is my code. <table id="table"> <?php for($i=0; $i<$totalbesin; $i++) { ?> <tr> <td

Ajax not sending var to url php

Engin Erdogan I'm trying to send a variable to the server, but the url doesn't go to the php file. Is it because I am not using the submit button? Here is my code. <table id="table"> <?php for($i=0; $i<$totalbesin; $i++) { ?> <tr> <td

"ajaxFunction is not defined" when sending AJAX request

Chirag Senjaliya I want to update another page userreg.phpfrom index.php. Here is my code: <html> <head> <title> User List </title> <link rel="stylesheet" href="css/datacss.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs

500 error when sending ajax request

Siraj I have read every article here and have not found an answer to my problem. I have an action in this controller: public class AccountController : Controller { [HttpPost] public JsonResult CheckUsername(string i_username) { var Membersh

500 error when sending ajax request

Siraj I have read every article here and have not found an answer to my problem. I have an action in this controller: public class AccountController : Controller { [HttpPost] public JsonResult CheckUsername(string i_username) { var Membersh

"ajaxFunction is not defined" when sending AJAX request

Chirag Senjaliya I want to update another page userreg.phpfrom index.php. Here is my code: <html> <head> <title> User List </title> <link rel="stylesheet" href="css/datacss.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs

500 error when sending ajax request

Siraj I have read every article here and have not found an answer to my problem. I have an action in this controller: public class AccountController : Controller { [HttpPost] public JsonResult CheckUsername(string i_username) { var Membersh

Bad symbol when sending request to PHP script

Taras Nikulin With my app, I send a request to a PHP script on a website. In my app, I configure a string similar to: name=John&pass=apricot&constKey=12345. Then, use a hash on that string and receive something like: blablabla25. It is now localKey. Then I sen

Bad symbol when sending request to PHP script

Taras Nikulin With my app, I send a request to a PHP script on a website. In my app, I configure a string similar to: name=John&pass=apricot&constKey=12345. Then, use a hash on that string and receive something like: blablabla25. It is now localKey. Then I sen

Request error when sending sms from php

Cody I am using api in india to send sms with curl <?php $url = "http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=Your message content."; $curl = curl_init($url); curl_setopt_

Request error when sending sms from php

Cody I am using api in india to send sms with curl <?php $url = "http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=Your message content."; $curl = curl_init($url); curl_setopt_

Bad symbol when sending request to PHP script

Taras Nikulin With my app, I send a request to a PHP script on a website. In my app, I configure a string similar to: name=John&pass=apricot&constKey=12345. Then, use a hash on that string and receive something like: blablabla25. It is now localKey. Then I sen

Request error when sending sms from php

Cody I am using api in india to send sms with curl <?php $url = "http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=Your message content."; $curl = curl_init($url); curl_setopt_

Ajax - function to check if url exists before sending request

Kyle Asaff I'm writing a function that fetches a json file from a website/server and saves it in local storage using the following code: function donators() { var jsonURL = "http://mywebsite.com/donators.json"; var xhr = new XMLHttpRequest(); xhr.o

Ajax - function to check if url exists before sending request

Kyle Asaff I'm writing a function that fetches a json file from a website/server and saves it in local storage using the following code: function donators() { var jsonURL = "http://mywebsite.com/donators.json"; var xhr = new XMLHttpRequest(); xhr.o

Ajax not sending request

Downey 123 I've been struggling with this simple problem for a long time, yes I tried to google the answer despite no luck, the problem is that my ajax request doesn't even send anything, so I guess it has something to do with the syntax , although it seems fi

Ajax not sending request

Downey 123 I've been struggling with this simple problem for a long time, yes I tried to google the answer though with no luck, the problem is that my ajax request doesn't even send anything, so I guess it has something to do with the syntax , although it seem

400 Bad Request when sending data using Ajax in Spring Framework

MJ82: Trying to pass JavaScript object to Spring MVC. I get a 400 Bad Request error. Tried all different ways but still no luck. I've attached the Controller, the objects I'm passing in JS and Java and the response. I will really appreciate. When I change the