dongquxiao8545 2012-09-26 19:18
浏览 51
已采纳

用PHP和Jquery替换Span数据

Im trying to do a simple span replacement using Jquery, php, and SQL. I think i coded this right but nothing is being displayed. I am using jQuery instead of $ to note the code to not collide with another script being used. How can i fix this:

jQuery:

jQuery.ajax({
    type: "POST",
    url: "http://www.mysite.com/report/reportScripts/getData.php",
    data: "&id=<?php echo $_GET['repId']; ?>",
    dataType: 'html';
    success: function(data){
        jQuery('.msgbox').html(response);
    }
}); 

PHP:

$con = mysql_connect('localhost', '****', '****');

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("*****", $con);

$sql="SELECT * FROM report_ordered WHERE referenceNum = '".$repId."'";

$result = mysql_query($sql);
$row = mysql_fetch_array($result);

echo $row['name'];

HTML Span:

<span id="msgbox"></span>
  • 写回答

2条回答 默认 最新

  • doudang2537 2012-09-26 19:21
    关注

    1. Success returns html in data, but you use response?

    success: function(data){
        jQuery('.msgbox').html(data); # you used response 
    }
    

    2. You use className to find msgbox, but msgbox has id

    success: function(data){
        jQuery('#msgbox').html(data); # you used .msgbox
    }
    

    3 . Use object as data: input in ajax

    data: { id: <?php echo $_GET['repId']; ?> },
    

    4. How do you fetch $repId? I hope you have some validation ?

    $sql="SELECT * FROM report_ordered WHERE referenceNum = '".$repId."'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀