【发布时间】:2013-12-21 06:30:52
【问题描述】:
function ChangeGallery(){
var GalleryName = $('.SubSubGalleryLock').text();
/*Send string to Data1.php and include Tags from Database*/
$.post("Data1.php", { Sections: GalleryName },
function(data){
$(".IncludeData").append(data);
});
/*send string to Data2.php and include Events data from Database*/
$.post("Data2.php",{ GallerySec: GalleryName },
function(response){
/*when i use alert method, this function works very well, why?*/
alert('SomeString');
var data = jQuery.parseJSON(response);
var ImageID = data[0];
var ImageSrc = data[1];
$(ImageID).click(function(){
$(".LargeImage").attr('src', ImageSrc);
});
});
};
在Data1.php中
/*give data from database1 and print to HTML File*/
if ($_POST['Sections']) == "String")
{ $results = mysql_query("SELECT * FROM Table1");
while($row = mysql_fetch_array($results))
{ echo $row['Tags']; }
在Data2.php中
/*give data from database2 and Use for events*/
if ($_POST['GallerySec']) == "String")
{ $results = mysql_query("SELECT * FROM Table2");
while($row = mysql_fetch_array($results))
{ echo json_encode($row); }
当我在客户端使用它时,Data1.php 工作得很好,但 Data2.php 仅在我编写时使用
alert('Some stringh');
之后
var data = jQuery.parseJSON(response);
行,它工作得很好,为什么?这是什么原因造成的?
【问题讨论】:
-
你想在
ImageID被点击后更改图片来源? -
它确实有效,但是当我使用 alert() 方法时
-
Works 意味着如果有警报语句,图像源已更改?
-
当我使用警报语句时,函数(响应)很好地从数据库中提供数据,但是当我不使用它时,它不起作用