如何显示retun调用所需的内容,而不是整个页面

时间:2016-11-05 14:25:08

标签: javascript php jquery ajax

我的index.php:

<?php 
$sContent.='<script src="https://code.jquery.com/jquery-1.12.4.js"></script>'; 
$sContent.='<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>'; 
$sContent.='<script src="in.js" type="text/javascript"></script>';

$id=2;
$sContent.='<div id="agree">Agree to terms: <input type="checkbox" id="agreed" value=1></div>';
$sContent.='<br><br><div class="show"></div>';

if($_GET['f'] == 'showInfo') 
{
   $sContent.=  'This is the info about item id: '.$_GET['id'];
}

$sAction = $_SERVER['PHP_SELF']."?id=".$id."&f=showInfo";
$sDest.= '<br><input class="'.$id.'" type="button" id="'.$id.'" name="'.$id.'" value="Click to show info about item '.$id.'" onClick="javascript:showInfo(\''.$sAction.'\');">';

$sContent.=  $sDest;
echo $sContent;
?>

在我的js文件中:

function showInfo (action)
{

    var aryAction = action.split('?');
    params = aryAction[1];
    var theUrl = 'index.php';
    alert( aryAction[1]);
    $.ajax ({
        url: theUrl,
        data: params,
        async:true,
        success: function (data, textStatus)
        {
            $('.show').html (data);
        }
    }); 
}

这显示div中的整个index.php与类&#39;显示&#39;。我不想要,我只需要&#39;这是关于商品ID的信息:2&#39;在那个div中,没有别的。

我一直在阅读其他类似帖子,也许我不应该使用ajax功能。关于如何做的任何想法?

非常感谢!!

1 个答案:

答案 0 :(得分:1)

您必须将HTML内容与字符串分开。

将这两件事放在import pygame pygame.init() white = [255,255,255] size = [960,540] screen=pygame.display.set_mode(size) pygame.display.set_caption("1a") done = False clock = pygame.time.Clock() Cursor = pygame.image.load('Cursor_normal.png') Cursor_Clicked = pygame.image.load('Cursor_Clicked.png') def draw_cursor(screen,x,y): if pygame.MOUSEBUTTONDOWN: screen.blit(Cursor_Clicked,(x,y-48)) else: screen.blit(Cursor,(x,y-48)) pygame.mouse.set_visible(0) while done==False: for event in pygame.event.get(): if event.type == pygame.QUIT: done=True screen.fill(white) pos = pygame.mouse.get_pos() x=pos[0] y=pos[1] draw_cursor(screen,x,y) pygame.display.flip() clock.tick(20) pygame.quit() / if条款中,然后就可以了:

else