2017-07-31 25 views
0

Codeigniterを使用して簡単なWebアプリケーションゲームをコーディングしました。私は混乱していますのはここAjaxリクエストが異なるブラウザで同じように動作しない

Ninja Gold

です。私はAjaxリクエストを使用して、場所のボタンから異なる金額を返すために私の異なるルートに行くことができるようにしています。私はバックグラウンドで連続的な音楽を持っていたいと思っていたので、この方法です。

問題はChromeでこのエラーが発生していることです。

XMLHttpRequest cannot load http://www.travterrell.com/ninjagold/Ninjas/cave. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://travterrell.com' is therefore not allowed access. 

私はもともとこのエラーを見つけたとき、私はこの問題を見上げると忍者ゴールドゲームは私の個人的なウェブサイト

のサブインデックスであるので、私はtravterrell.comのインデックスファイルにこのコードを挿入するために必要なことがわかっていました
<?php header('Access-Control-Allow-Origin: *'); ?> 

私もこれに私の.htaccessファイルを変更するように指示された:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /ninjagold 

    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 
    #previously this would not have been possible. 
    #'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Submitted by: Fabdrol 
    #Rename 'application' to your applications folder name. 
    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

具体的にライン3、私はベースを再書いています。最初はこれで問題は解決しましたが、Chromeでゲームが動作しないことがあり、デスクトップ上のSafariで動作することがあります。それはSafariの携帯電話で動作しますが、金を受け取ったり消すためにボタンをクリックしたときの効果音は機能しません。 Chromeはモバイルでは動作しません。問題は何ですか?

+0

.. –

答えて

0

なぜCORSを正直なものにするのかはわかりません。 in this answerのように.htaccessファイルに挿入します。 this answerもチェックしてください(前と同じ質問)。答えから

引用:私は私自身のZend Frameworkの2プロジェクトで使用2つの.htaccessファイル以下

<IfModule mod_headers.c> 
    Header set Access-Control-Allow-Origin "*" 
</IfModule> 

。アプリケーションのルートにある最初のものは、Apacheの仮想ホストを適切にセットアップすることを忘れた場合には非常に役に立ちます。すべてをパブリックフォルダのindex.phpファイルにリダイレクトします。

2番目のファイルは、ZF2のデフォルト.htaccessです。魅力のように動作します。 CodeIgniter 2(数年前)を試してみたときから、同じファイルを使用しました。

明らかに、最初のファイルのベースを/ ninjagoldの場所に書き換える必要があります。ただし、アプリケーションにエントリポイントとして/publicフォルダがある場合は、/ninjagold/publicに書き換えてください。

ルート(/)すでにクロームで働いリンクAJAXを考えると.htaccess

RewriteEngine On 

# If URL to the application is http://foo.com/path/to/ZendSkeletonApplication/ 
# the set the base to /path/to/ZendSkeletonApplication/ 
RewriteBase/

# Remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# Below is ZF2 default 
RewriteRule ^\.htaccess$ - [F] 
RewriteCond %{REQUEST_URI} ="" 
RewriteRule ^.*$ public/index.php [NC,L] 

RewriteCond %{REQUEST_URI} !^/public/.*$ 
RewriteRule ^(.*)$ public/$1 

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^.*$ - [NC,L] 

RewriteRule ^public/.*$ public/index.php [NC,L] 

/public/.htaccess

RewriteEngine On 

# Remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# The following rule tells Apache that if the requested filename 
# exists, simply serve it. 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do 
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work 
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution. 
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
RewriteRule ^(.*) - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 
+0

だから、最初の.htaccessファイルが正常に正しい動作するはず?私はCodeIgniterが新しく、私は.htaccessファイルに関する詳細情報を探しています。 –

+0

それはあなたがしようとしていることに依存しますが、これは少し不明です。あなたはAJAX関数が動作していないと言っていますが、あなたの '.htaccess'ファイルについてのみ話を進めています。これは '500の内部サーバーエラー'応答を受け取っていると信じる(私)、あるいは '404が見つかりませんでした。 'おそらく後者です。しかし、もしあなたが "website.com/ninjagold/get_me_data"のようなものにリンクしているのであれば、プロジェクトのルートにある最初の.htaccessがウェブサイトのルートではないので、 ninjagold/to/ninjagold/public ... – Nukeface

+0

主にZF2ベースの私の知識とは別に、あなたの周りを素早く見て、[this](https://stackoverflow.com/questions/40003236/)を見つけました。 codeigniter-web-config-or-htaccess-index-php-rewrite-inside-a-subdirectory)は、あなたの正確な問題であるようです。これは、Codeigniterアプリ内のCodeigniterアプリに関するものです(つまり、本質的には、サブディレクトリ内のアプリ)。次のことについてはわかりませんが、[役立つかもしれません](https://serverfault.com/questions/820040/codeigniter-is-not-working-after-primary-domain-to-subfolder)。 – Nukeface

関連する問題