0

PHPスクリプトにajax投稿を行い、大量のhtmlを返すWebアプリがあります。html には、画像とデータの表があります。私がやろうとしているのは、画像を残りの html から分離して、別の場所に表示できるようにすることです。

$.ajax({      
  type: "POST",
  url: 'api/service_connector.php',
  data: { selectedmodel: requestdata },
  beforeSend: function() {},
  success: function(returneddata) {                             
  var $response=$(returneddata);
  var test = $response.filter('.testimage').html();      
  alert(test);  
  }                     
});

成功関数で、returneddata 変数全体にアラートを出すだけであれば、すべて正常に動作します。したがって、投稿自体が機能しており、すべてが適切に返されていることがわかります。直面している画像タグを取得するだけです。また、Googleで見つけた他の「方法」をたくさん試しました。例えば、

alert($(returneddata).find('.testimage').html());
4

3 に答える 3

0

あなたはjqueryで遊んだことがあります$.remove()か?

例えば:

<div class="container">
 <img class="theimage" src=".." />
</div>

...

$(".theimage").prop("src");   // get anything valuable from image first for future use
$(".theimage").remove();      // remove the image from there
于 2013-05-07T22:14:55.633 に答える
0

phpファイルで

テーブル データの最初と最後に区切り文字 ('|') を追加します

ajax関数で

「|」の間のコンテンツを取得します シンボル。

画像タグでも同じことができます

于 2013-05-10T11:12:56.563 に答える
0

試すdetach()

$.ajax({      
  type: "POST",
  url: 'api/service_connector.php',
  data: { selectedmodel: requestdata },
  beforeSend: function() {},
  success: function(returneddata) {                             
      var $response=$(returneddata);
      var $testimage = $response.find('.testimage');
      $testimage.detach();
      alert($('<p>').append($response).html());  
  }                     
});

http://jsfiddle.net/2H2FT/

于 2013-05-07T22:10:44.883 に答える