Jquery .Ajax()返回错误0 [英] Jquery .Ajax() Return Error 0

查看:159
本文介绍了Jquery .Ajax()返回错误0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在index.html中用登录表单写了javascript。当我提交时,我远程调用运行IIS7的服务器的Web服务。当我在Dreamweaver中使用Live Code运行它时,我收到了一个响应,但是当我使用相同的代码在常规浏览器中运行index.html时,我得到的错误类型为0。当我复制这些文件并将其托管在服务器上,并将Web服务路径更改为localhost并使用broswer打开它时,也会发生同样的情况。



我怀疑它与类似的访问权限有关。
这里是代码,如果需要更多信息,请让我知道。

  $(#ButtonLogin)。点击(函数(事件){
$ .ajax({
类型:POST,
url:serverPath +/test.asmx/LogIN,
data: {'UserName':''+ $('#TextBoxUsername')。val()
+'','pwd':'+ $('#TextBoxPassword')。val()+'} ,
contentType:application / json; charset = utf-8,
dataType:json,
success:function(msg){
AjaxLogInSucceeded(msg);} ,
错误:AjaxLogInFailed
});
});


解决方案

调试ajax问题看起来很复杂,但如果您还记得你只是发送一个URL调试变得更容易。在处理这些类型的问题时,我使用FirefoxLive HTTP Headers扩展来查看正在发送到服务器的CGI参数的URL。我可以想象,当运行由Dreamweaver等系统生成的代码时,这可能非常有用。

然后,您可以将ajax URL插入浏览器(或wget)并看看有什么回来。或者,如果我也在编写后端代码(通常情况下),我可以打印出调试状态消息以帮助识别问题。



祝你好运!


I wrote javascript in index.html with a login form. When I submit, I call a web service remotely to a server running IIS7. I get back a response when I run it with "Live Code" in Dreamweaver but when I run the index.html in a regular browser with the same code I get error type "0". The same thing happen when I copy those file and host it on the server and changing the web service path to localhost and opening it with a broswer.

I am suspecting that it has to do with access permission of something similar. Here is the code, if more information is needed please let me know

$("#ButtonLogin").click(function (event) {
    $.ajax({
        type: "POST",
        url: serverPath + "/test.asmx/LogIN",
        data: "{'UserName': '" + $('#TextBoxUsername').val() 
          + "', 'pwd': '" + $('#TextBoxPassword').val() + "'}", 
        contentType: "application/json; charset=utf-8",
        dataType: "json", 
        success: function (msg) { 
            AjaxLogInSucceeded(msg);} ,
        error: AjaxLogInFailed
    });
});

解决方案

Debugging ajax issues can seem complicated, but if you remember that you're just sending off a URL debugging becomes easier. When dealing with these sorts of problems I use the Firefox "Live HTTP Headers" extension to see the URL with the CGI paramters that are being sent to the server. I'd imagine that this could be quite helpful when running code generated by a system like Dreamweaver.

You can then just plug your ajax URL into your browser (or wget) and see what comes back. Or if I'm writing the backend code also (usually the case) I can print out debugging status messages to help to identify the problem.

good luck!

这篇关于Jquery .Ajax()返回错误0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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