对ajax响应的echo查询

时间:2014-02-18 11:06:59

标签: php jquery

我正在尝试通过AJAX发送php表单数据(没有刷新)并以新的形式显示数据。我回应查询,但它没有工作。在AJAX响应中,它向我显示了getReportAj表单。代码如下:

的Javascript

function getReport()
{
    var dataString = "grNo=" +$(".grNo").val(); 
    $.ajax({
        type: "GET",
        url: "getReportAj.php",
        data: dataString,
        success:function(data)
        {
            $('#result').html(data);
        }
    });
}

getReportAj.php

<?php
include "include/config.inc.php";
if(!isset($_SESSION['s_activName']) && !isset($_SESSION['s_userType']) || isset($_SESSION['s_userType']) && $_SESSION['s_userType'] == 'Student') {
    $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
    header("Location:checkLogin.php");
}
else {
    if(isset($_REQUEST['submit'])) {
        $selectReport = "SELECT * from gradeterm1
                           WHERE studentId = ".$_POST['studentId']."
                           AND termValue = 1
                        LEFT JOIN studentmaster ON studentmaster.studentId = gradeterm1.studentId";
        $selectReportRes = mysql_query($selectReport);
        if($reportRow = mysql_fetch_array($selectReportRes)); {
            $eReadingPro   = $reportRow['eReadingPro'];
            $eReadingFlu   = $reportRow['eReadingFlu'];
            $eReadingCom   = $reportRow['eReadingCom'];
            $eWritingCre   = $reportRow['eWritingCre'];
            $eWritingHan   = $reportRow['eWritingHan'];
            $eWritingGra   = $reportRow['eWritingGra'];
            $eWritingSpe   = $reportRow['eWritingSpe'];
            $eWritingVoc   = $reportRow['eWritingVoc'];
            $ewSpeakinCon  = $reportRow['ewSpeakinCon'];
            $ewSpeakinRec  = $reportRow['ewSpeakinRec'];
            $ewSpeakinCla  = $reportRow['ewSpeakinCla'];
            $eListingComp  = $reportRow['eListingComp'];
            $eListingCon   = $reportRow['eListingCon'];
            $extraReading  = $reportRow['extraReading'];
            $activityPro   = $reportRow['activityPro'];
            $hiReadingPro  = $reportRow['hiReadingPro'];
            $hiReadingFlu  = $reportRow['hiReadingFlu'];
            $hiReadingCom  = $reportRow['hiReadingCom'];
            $hiWritingCre  = $reportRow['hiWritingCre'];
            $hiWritingHan  = $reportRow['hiWritingHan'];
            $hiWritingGra  = $reportRow['hiWritingGra'];
            $hiWritingSpe  = $reportRow['hiWritingSpe'];
            $hiWritingVoc  = $reportRow['hiWritingVoc'];
            $hiwSpeakinCon = $reportRow['hiwSpeakinCon'];
        }
    }
}
include("./bottom.php");
$smarty->display('getReportAj.tpl');
?>

1 个答案:

答案 0 :(得分:0)

<script>
function getReport()
    {
        var dataString = "grNo=" +$(".grNo").val(); 
        $.ajax({
          type: "GET",
          url: "getReportAj.php",
          data: dataString,
          success:function(data)
          {
            $('#result').html(data);
            console.log(data);
        }
      });
    }
</script>

成功事件..放入console.log(数据)然后运行脚本并检入控制台。