火狐的jQuery的Ajax调用错误 [英] Firefox Ajax jquery call error

查看:109
本文介绍了火狐的jQuery的Ajax调用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,但我有问题,让它在Firefox工作。该应用程序临危从教育应用(网站被显示在共享窗口),它应该从.NET Web服务返回值的JavaScript调用。的值必须在相同的函数临危呼叫返回。该Web服务返回值可以是真的,假的串或有时从数据库的值。该websevice支持AJAX。

I am developing an application but I am having problems to get it to work in Firefox. The application recieves javascript calls from educational applications (websites that are showed in shared window) and it is supposed to return values from a .net webservice. The values must be returned in the same function that recieves the call. The webservices return values are strings that can be true,false or sometimes a value from a database. The websevice supports ajax.

由于我不知道究竟如何使用javascript我使用jquery-1.3.2调用web服务。

Since I dont know exactly how to call a webservice using javascript I am using jquery-1.3.2.

在code·贝娄的作品在Internet Explorer,但Firefox上使用时,它就像它不会等待调用返回一个值,尽管异步:FALE

The code bellow works on Internet Explorer but when used on Firefox it is like it wont wait for the call to return a value despite the async:fale.

function API_LMSInitialize(param)
{
  res="true";
  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "../../../GateWay/WebService.asmx/LMSInitialize",
    data: "{'courseid':'"+courseid+"','userid':'"+userid+"'}",
    dataType: "json",
    async: false,
    success: function(msg) { res = msg; },
    error: function(){ res="false"; }
  });

  return res;
}

有什么建议?

推荐答案

不使用异步您最好的选择:假的,因为这挂断浏览器,如果因任何原因ajax调用失败,用户将不得不关闭浏览器窗口。最好的选择是传递一个回调函数到您现有的API_LMSInitialize功能,这将是 呼吁Ajax调用成功。你也将不得不重新工作,你的一些调用code和推动这一到回调函数。

Your best option is not to use asynch:false as this hangs up the browser and if for any reason the ajax call fails the user will have to close the browser window. Your best option is to pass a callback function into your existing API_LMSInitialize function which will be called on success of the ajax call. You will also have to re-work some of your calling code and move this into the callback function.

例如

API_LMSInitialize( 'someParam', callbackFn);


function API_LMSInitialize(param, callback)
{

  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "../../../GateWay/WebService.asmx/LMSInitialize",
    data: "{'courseid':'"+courseid+"','userid':'"+userid+"'}",
    dataType: "json",
    async: false,
    success: function(msg) { callbackFn(msg) },
    error: function(){ res="false"; }
  });

}

function callbackFn(msg){

     //do something with the returned data
}

这篇关于火狐的jQuery的Ajax调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆