开发者

Jquery qtip ajax issue

I am trying to post the value of an input box (In this case a imdb link) to my imdbgrabber.php page and have it return the info of that movie into a qtip box.

EDIT: View here http://movieo.no-ip.org/ Hover the images and you will see the error.

Everything works fine until i try and post the variable to the imdbgrabber page. This is the code.

Javascript:

 var link = $("#link").val();
    var imdbLink = 'link='+ link;

$(".moviebox").qtip({
   style: { name: 'cream' },
   content: {
     method: 'GET',
     data: imdbLink,
     url: '/includes/imdbgrabber.php',
     text: '<img class="throbber" src="/images/loading.gif" alt="Loading..." />'
   },
   position: {
         corner: {
           target: 'bottomright',
          tooltip: 'bottomleft'
        }
      }
});

HTML:

 <!--start moviebox-->
  <div class="moviebox">
  <a href="#">
  <img src="http://1.bp.blogspot.com/_mySxtRcQIag/S6deHcoChaI/AAAAAAAAObc/Z1Xg3aB_wkU/s200/rising_sun.jpg" />
  <form method="get" action="">
              <input type="text" name="link" id="link" style="display:none" value="http://www.imdb.com/title/tt0367882"/>
 </form>
  </a>
  </div>
  <!--end moviebox-->

and finally the php:

<?php

$url=$_GET['link'];

//$url = 'http://www.imdb.com/title/tt0367882/';

//get the page content
$imdb_content = get_data($url);

//parse for product name
$name = get_match('/<title>(.*)<\/title>/isU',$imdb_content);
$director = strip_tags(get_match('/<h5[^>]*>Director:<\/h5>(.*)<\/div>/isU',$imdb_content));
$plot = get_match('/<h5[^>]*>Plot:<\/h5>(.*)<\/div>/isU',$imdb_content);
$release_date = get_match('/<h5[^>]*>Release Date:<\/h5>(.*)<\/div>/isU',$imdb_content);
$mpaa = get_match('/<a href="\/mpaa">MPAA<\/a>:<\/h5>(.*)<\/div>/isU',$imdb_content);
$run_time = get_match('/Runtime:<\/h5>(.*)<\/div>/isU',$imdb_content);
$rating = get_match('/<div class="starbar-meta">(.*)<\/div>/isU',$imdb_content);

////build content
//$content = '<h2>Film</h2><p>'.$name.'</p>'
//          . '<h2>Director</h2><p>'.$director.'</p>'
//          . '<h2>Plot</h2><p>'.substr($plot,0,strpos($plot,'<a')).'</p>'
//          . '<h2>Release Date</h2><p>'.substr($release_date,0,strpos($release_date,'<a')).'</p>'
//          . '<h2>MPAA</h2><p>'.$mpaa.'</p>'
//          . '<h2>Run Time</h2><p>'.$run_time.'</p>'
//          . '<h2>Full Details</h2><p><a href="'.$url.'" rel="nofollow">'.$url.'</a></p>';



//gets the match content
function get_match($regex,$content)
{
    preg_match($regex,$content,$matches);
    return $matches[1];
}

//gets the data from a URL
function get_data($url)
{
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
?>

  <!--start infobox-->
    <div class="info"> 
  <span>
  <?php echo '<strong>'.$name.'</strong>' ?>
  </span>

  <img src="http://1.bp.blogspot.com/_mySxtRcQIag/S6deHcoChaI/AAAAAAAAObc/Z1Xg3aB_wkU/s200/rising_sun.jpg" /开发者_StackOverflow社区> 
  <div class="plot">
  <?php echo ''.substr($plot,0,strpos($plot,'<a')).'</div>' ?>
  </div>

  <div class="runtime">
  <?php echo'<strong>Run Time</strong><br />'.$run_time.'</div>' ?>
  </div>
<div class="releasedate">
<?php echo '<strong>Release Date</strong><br />'.substr($release_date,0,strpos($release_date,'<a')).'</div>' ?>
</div>
<div class="director">
<?php echo '<strong>Director</strong><br />'.$director.'' ?>
</div>
  <div class="rating">
  <?php echo '<strong>Rating</strong><br />'.$rating.'' ?>
  </div>
  </div>
  <!--end infobox-->

I am sure it is a simple mistake somewhere but after hours of looking i thought i would ask the experts.


According to the documentation, the data for qtip when fetching via AJAX needs to be key-value pairs. Try this:

var link = $("#link").val();
var imdbLink =  { "link" : link };  // note change to data...

$(".moviebox").qtip({
   style: { name: 'cream' },
   content: {
     method: 'GET',
     data: imdbLink,   // you could make this { "link" : link }
     url: '/includes/imdbgrabber.php',
     text: '<img class="throbber" src="/images/loading.gif" alt="Loading..." />'
   },
   position: {
         corner: {
           target: 'bottomright',
          tooltip: 'bottomleft'
        }
      }
});

Also it appears that your get_match routine is improperly indexing into the matches array. Arrays are zero-based, so the first match is the match at index 0, not one. In fact, you can only ever have a single match given your regular expressions since you only have one grouping expression.

Try changing it to this:

//gets the match content  
function get_match($regex,$content)  
{  
    preg_match($regex,$content,$matches);  
    return $matches[0];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜