2010-03-24 117 views
0

我想将输入框的值(在这种情况下是imdb链接)发布到我的imdbgrabber.php页面,并让它将该电影的信息返回到qtip框中。jquery qtip ajax问题

编辑︰这里查看http://movieo.no-ip.org/将图像悬停,你会看到错误。

一切工作正常,直到我尝试并将该变量发布到imdbgrabber页面。这是代码。

的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--> 

终于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" /> 
    <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--> 

我相信这是一个简单的错误的地方,但寻找我以为小时后我会问专家。

回答

1

根据文档,当通过AJAX获取时,qtip的数据需要是键值对。试试这个:

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' 
     } 
     } 
}); 

此外,它似乎是你的get_match例程不正确地索引到匹配数组。数组是基于零的,所以第一个匹配是索引0处的匹配,而不是一个匹配。实际上,由于您只有一个分组表达式,因此只能针对您的正则表达式进行单个匹配。

尝试将其更改为这样:

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

还是同样的问题,检查这里:HTTP://movieo.no-ip.org/。悬停图像看看会发生什么 – user272899 2010-03-24 12:36:49

+0

我明白了。问题不在于请求,而在于你的代码。将更新。 – tvanfosson 2010-03-24 13:29:55

+0

改变了这个问题。 ajax发布的信息很好,所以这是一个问题的地方 – user272899 2010-03-24 13:42:13