gpt4 book ai didi

php - jQuery 函数调用 ajax 不起作用/返回任何内容

转载 作者:行者123 更新时间:2023-12-02 19:18:49 26 4
gpt4 key购买 nike

我正在使用 icenium 为移动设备编写一个应用程序(不是 Web 应用程序),它使用 javascript 等而不是其 native 语言。

该应用程序显示数据库中的行,并显示事件。然后,用户单击一个事件,该事件会显示有关该事件的更多信息,但是我在从 js 函数调用 ajax 时遇到问题,如下所示:

function showSingle(itemId){

//document.write(itemId);
$('#output').fadeOut();
$('#single').fadeIn("fast");
$.ajax({
url: 'http://dev.123456789.co.uk/getSingle.php',
dataType: 'jsonp',
data: { dbId: itemId },
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){

var linkedPageSingle = '<h2>'+item.eventName+'</h2>'
+ '<p>Description: '+item.description+'</p><p>Type: '
+ item.type+'</p><p id="pageid">'+item.id+'</p>';

$('#single').append(linkedPageSingle);
// pageId = $('#pageid').html();
$('#single').text('debugdebug.');
},
error: function(){
$('#single').text('There was an error loading the data.');
}
});
}

这不会返回任何数据,它甚至不会返回 $('#single').text('debugdebug.');那么ajax调用一定有问题吗?还有

error: function(){
$('#single').text('There was an error loading the data.');
}

不输出。你能发现其中的错误吗?该函数的调用在这里:

var linkedPage = '<h2><a href="#" onClick="showSingle('+item.id+')">'+item.eventName+'</a></h2>'
+ '<p>Description: '+item.description+'</p><p>Type: '
+ item.type+'</p><p id="pageid">'+item.id+'</p>';

它位于页面的 document.ready 部分,在 ajax 方法内(有效)。

getSingle.php:

<?php

/*
* Script to connect to database and pull out information for app!
*/

include 'connect.php';

$dbId = $_POST['dbId'];
$query = mysql_query("SELECT * FROM calTest where `id`='$dbId'");
$records = array();

while($row = mysql_fetch_assoc($query)) {
$records[] = $row;
}

echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';

?>

看不出我哪里出错了,谢谢!

最佳答案

我认为问题出在数据发布

$dbId = $_POST['dbId'];

echo $_GET['jsoncallback'];

您正在同时使用 get 或 post 方法

关于php - jQuery 函数调用 ajax 不起作用/返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12778205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com