1

私はこのコードを持っています:

<div id="quote">
  <p>
    Click on image please.
  </p>
</div>    
<img class="post" src="positif.png" title="rate this positive" onclick="positif(this);">

画像がクリックされると、次の関数が呼び出されます。

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
   var jq = jQuery.noConflict(true);
</script>
<script type="text/javascript">
  function positif(obj) {
    var url = obj.parentNode.valueOf('href');
    var nama = obj.parentNode.innerText;
    alert(url);
    jq("#quote p").load("retrain/pos.php?url=" + url + "&nama=" + nama);
  }    
</script>

Thing は次のスクリプトloadを呼び出します。pos.php

$url = $_GET["url"];
$nama = $_GET["nama"];
$nama2 = str_replace(str_split('\\/:*?"<>|()'), '', $nama);
$post = '../cat/statistika/S_' . $nama2 . '.txt';

    $current = file_get_contents($url);
    if (file_get_contents($url)) {
        $current2 = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $current);
        $current3 = preg_replace('#<style(.*?)>(.*?)</style>#is', '', $current2);
        $current4 = strip_tags($current3);
        $current5 = preg_replace('/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', '', $current4);
        file_put_contents($post, $current5);
        echo "Rated positive, Thanks for your response!";
    } else {
        echo 'Sorry, connection failed. Try again later.';
    }

彼らは正常に動作します。しかし、そこに慣れてからfile_put_contentは時間がかかり、put_content成功するまでに「変化」は何も表示されません。ひいては、PHP(またはjavascript?)が最終的にRated positive blah2.

これを関数の最後に入れpositif(obj)ます:

jq('body').ajaxStart(function() {
jq('#loading').show();
}).ajaxComplete(function() {
jq('#loading').hide();
});

div上の別のものと同様にdiv#quote p、これで:

<div id="loading">
  <img id="loading-image" src="loading_thing.gif" alt="Loading..." style="display: none"/>
</div>

うまくいきませんでした。私はここで何をしなかったのですか?

4

3 に答える 3

0

これを行の後に置くと、うまくいくと思いますalert(url);

jq('#loading').fadeIn(); // Just esthetic, you could use .show()
jq("#quote p").load("retrain/pos.php?url=" + url + "&nama=" + nama,
function () {
     jq('#loading').fadeOut(); // Just esthetic, you could use .hide()
});

お役に立てれば幸いです。

于 2013-09-09T03:28:53.580 に答える
0

ajaxStart doc から:

jQuery 1.8 以降、.ajaxStart() メソッドはドキュメントにのみ添付する必要があります。

だから試してください:

jq('document').ajaxStart(function() {
  jq('#loading, #loading-image').show();
}).ajaxComplete(function() {
  jq('#loading, #loading-image').hide();
});
于 2013-09-09T03:22:12.263 に答える
0

画像のプレースホルダーも表示することを忘れないでください

jq('body').ajaxStart(function() {
    jq('#loading, #loading-image').show();
}).ajaxComplete(function() {
    jq('#loading, #loading-image').hide();
});
于 2013-09-09T03:22:22.723 に答える