火狐的jQuery的Ajax调用错误

编程入门 行业动态 更新时间:2024-10-26 20:33:12
本文介绍了火狐的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 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调用错误

本文发布于:2023-11-24 19:22:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626497.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:火狐   错误   jQuery   Ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!