gpt4 book ai didi

javascript - 类型错误 : jQueryxxxxxx is not a function

转载 作者:行者123 更新时间:2023-11-29 21:31:27 25 4
gpt4 key购买 nike

首次打开移动应用主页时返回错误

"TypeError: Jqueryxxxxxx is not a function" although it shows the API callback results "jQuery111309512500500950475_1459208158307({"code":1,"msg":"Ok","details":{"data"..." according to Firebug.

我必须打开不同的应用程序页面,然后返回主页才能看到已解析的特色商家。

JS代码

case "page-home":
callAjax('getFeaturedMerchant','');
break;
case "getFeaturedMerchant":
displayFeaturedRestaurant( data.details.data ,'list-featured');
break;
case "getFeaturedMerchant":
createElement('list-featured','');
break;

API PHP代码

public function actiongetFeaturedMerchant()
{
$DbExt=new DbExt;
$DbExt->qry("SET SQL_BIG_SELECTS=1");

$start=0;
$limit=200;

$and='';
if (isset($this->data['restaurant_name'])){
$and=" AND restaurant_name LIKE '".$this->data['restaurant_name']."%'";
}

$stmt="SELECT a.*,
(
select option_value
from
{{option}}
WHERE
merchant_id=a.merchant_id
and
option_name='merchant_photo'
) as merchant_logo

FROM
{{view_merchant}} a
WHERE is_featured='2'
AND is_ready ='2'
AND status in ('active')
$and
ORDER BY sort_featured ASC
LIMIT $start,$limit
";

if (isset($_GET['debug'])){
dump($stmt);
}

if ($res=$DbExt->rst($stmt)){
$data='';

foreach ($res as $val) {
$data[]=array(
'merchant_id'=>$val['merchant_id'],
'restaurant_name'=>$val['restaurant_name'],
'logo'=>AddonMobileApp::getMerchantLogo($val['merchant_id']),
);
}
$this->details=array(
'data'=>$data
);
$this->code=1;$this->msg="Ok";
$this->output();
} else $this->msg=$this->t("No Featured Restaurant found");
$this->output();
}

我对导致此错误的原因以及解决方法感到困惑。

编辑:添加了完整的 callAjax 函数

function callAjax(action,params)
{

/*add language use parameters*/
params+="&lang_id="+getStorage("default_lang");

dump(ajax_url+"/"+action+"?"+params);

ajax_request = $.ajax({
url: ajax_url+"/"+action,
data: params,
type: 'post',
async: false,
dataType: 'jsonp',
timeout: 6000,
crossDomain: true,
beforeSend: function() {
if(ajax_request != null) {
/*abort ajax*/
hideAllModal();
ajax_request.abort();
} else {
},
complete: function(data) {
ajax_request=null;
hideAllModal();
},
success: function (data) {
dump(data);
if (data.code==1){
switch (action)
{

case "getFeaturedMerchant":
displayFeaturedRestaurant( data.details.data ,'list-featured');
//$(".result-msg").text(data.details.total+" Restaurant found");
$(".result-msg").text(data.details.total+" "+ getTrans("Featured Restaurants found",'restaurant_found') );
break
)
else {
/*failed condition*/
switch(action)
{
case "getFeaturedMerchant":
createElement('list-featured','');
//$(".result-msg").text(data.msg);
break;
}
},
error: function (request,error) {
hideAllModal();
if ( action=="getLanguageSettings" || action=="registerMobile"){
} else {
onsenAlert( getTrans("Network error has occurred please try again!",'network_error') );
}
}
}};

调用 URL 是:

http://domain.com/mobileapp/api/getFeaturedMerchant?

最佳答案

这其实是jQuery在使用JSONP时处理abort方法的方式的问题,我之前也遇到过。

基本上,JSONP 的工作原理是向 DOM 添加一个脚本标记,并添加一个回调,它会在执行时触发。

与 AJAX 不同,script 标记生成的请求无法取消,因此当您像下面这样调用 abort 时,它只能起到一定的作用。

ajax_request.abort();

jQuery 将取消设置它注册的全局回调,在您的例子中为 jQuery111309512500500950475_1459208158307,但它无法阻止脚本在加载时尝试运行它。因此,当它尝试调用现在未定义的函数时,您会收到错误。

就我个人而言,我认为 jQuery 应该将这些全局处理程序设置为或可以选择将这些全局处理程序设置为空函数或其他东西,但事实并非如此。对于您的情况,如果可能的话,如果您只打算在发送之前中止请求,我建议您避免发出请求。

关于javascript - 类型错误 : jQueryxxxxxx is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36274120/

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