jqury ajax 直接获取数据库信息,使用jQuery Ajax从数据库加载信息

问题

我尝试使用以下

// Start method 1

var grbData = $.ajax({

type : "GET",

url : "http://grb.sonoma.edu:81/getgrbs.php",

data : "start=0&perPage=3"}).responseText;

$("#ajaxDiv").html(grbData);

// End method 1

// Start method 2

$.get("getgrbs.php", { start : 0, perPage : 3},

function(data) {

$("#tst").html(data);

}, "html");

// End method 2

在此页面上:http :

//grb.sonoma.edu :

81/paging.php从数据库加载数据。方法1仅在IE8中有效,但仅在刷新页面后才有效。首次加载页面时,我收到“完成此操作所需的数据尚不可用”。错误。

我更喜欢方法1的原因是因为它使我可以访问表中的各个行。例如,每一行都有一个“突发”类。我在用

$(".burst").click(function() {

$(".burst").css("background-color", "");

$(this).css("background-color", "yellow");

});

单击时更改所选行的颜色。这似乎仅适用于方法1,而不适用于方法2。

以上所有代码都封装在$(document).ready()中。我努力了

$("#ajaxDiv").load("getgrbs.php", { start : 0, perPage : 3});

但是我得到的结果类似于方法2。

我如何才能使click函数与方法2一起使用,或者使方法1在所有浏览器上都能正常工作而不进行刷新?感谢您提供的任何帮助。

我需要在ajax中进行此操作(尝试过没有jquery且没有运气的ajax),因为页面上还有其他内容不会随着用户翻阅数据而改变。

解决方案的附录(更好的解决方案)

成功使用“成功”之后,我注意到单击行并进行bg颜色更改的功能消失了。因此,我做了以下工作,看来可行。不知道这是否是最好的方法。

var grbData = $.ajax({

type : "GET",

url : "http://grb.sonoma.edu:81/getgrbs.php",

data : "start=0&perPage=3",

dataType : 'html',

success: function (data) {

$("#ajaxDiv").replaceWith(data);

startInteraction();

}

});

function startInteraction() {

$(".burst").click(function() {

$(".burst").css("background-color", "");

$(this).css("background-color", "yellow");

});

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值