2016-10-17 12 views
3

これで、このクエリが尋ねられていないことが分かりました。最後に、私のクエリに切り替え可能な答えを見つけることができません。
私はapache2サーバー上で私は永続的に特定のPHPファイルにディレクトリやファイルを指し続けるために、ルートディレクトリ内の.htaccessファイルの書き換えルールを有効にしましたが、これは完全に動作しますが、URLがディレクトリを変更するとajaxスクリプトは失敗します。ここURLディレクトリが変更されたときに、AjaxがPHPにリクエストを送信しない

は、PHPスクリプト[テスト...]

<?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; 
} 

?> 

そして、ここでは、Ajaxのスクリプト

<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> 
+0

私は本当に関連していることを忘れています、ありがとう... – Zuckerberg

答えて

2

が仕事を達成するために絶対URLを使用してくださいです..です 下記のコードを参照してください

<?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> 
+0

それは完璧に働いて... – Zuckerberg

関連する問題