Chrome和Ajax [英] Chrome and Ajax

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

问题描述

您好,我已经完成了自动填充扩展程序功能,并且在IE上可以正常使用,但是在Google Chrome浏览器中运行时,它无法正常运行.有人可以帮我吗?

这是我的代码:
在HTML中:

Hi, I already made an autocomplete extender functionality and it is working fine on IE, but when running it in Google Chrome, it is not working. So can anyone help me please?

This is my code :
In Html:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1"  runat="server">
     <asp:ToolkitScriptManager ID="ScriptManager2" runat="server"  EnablePartialRendering="true" > 
    <services> 
    <asp:ServiceReference Path="DataService.asmx" /> 
    </services> 
     
    <div>
    
        <asp:TextBox ID="TextBox1" runat="server">
        <asp:AutoCompleteExtender BehaviorID="AutoCompleteExtenderBehaviour" ID="TextBox1_AutoCompleteExtender" runat="server" 
          MinimumPrefixLength="1"  CompletionSetCount="10"  DelimiterCharacters=""  ShowOnlyCurrentWordInCompletionListItem="true" Enabled="True" ServicePath="DataService.asmx" TargetControlID="TextBox1" ServiceMethod="GetCities">
        <animations>
                <onshow>
                    <sequence>
                         <hideaction visible="true"></hideaction>
                         <fadein duration=".50" fps="10" />
                    </sequence>
                </onshow>
                <onhide>
                    <sequence>
                         <hideaction visible="true"></hideaction>
                         <fadeout duration=".50" fps="10" />
                    </sequence>
                </onhide>
           </animations>
        
       
        <br />
        <br />
        
    
    </div>
    </form>
</body>
</html>



在Webservice中:



In Webservice :

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data;
using System.Collections.Generic;

[WebService(Namespace = "http://temf.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 [System.Web.Script.Services.ScriptService]
public class DataService : System.Web.Services.WebService {

     public static IList<string> _cityList;
    public DataService () {

       //InitializeComponent(); 
    }

    [WebMethod]
    public string[] GetCities(string prefixText, int count)
    {

        //Gets the city list
       IList<string>  cityList = GetCityData();

        //using linq to select the cities based on the prefix text
        var result = from city in cityList.AsEnumerable()
                     where city.ToUpper().StartsWith(prefixText.ToUpper())
                     select city;
        //return the result as a string[] by taking only the top n
        return result.Take(count).ToArray<string>();
    }
    private IList<string> GetCityData()
    {
        if (_cityList == null)
        {
            CreateCityList();
        }

        return _cityList;
    }
    private static void CreateCityList()
    {
        _cityList = new List<string>();
        _cityList.Add("Boston");
        _cityList.Add("NewYork");
        _cityList.Add("California");
        _cityList.Add("New Jersey");
        _cityList.Add("Denver");
        _cityList.Add("Detroit");
        _cityList.Add("Idaho");
        _cityList.Add("Ohio");
        _cityList.Add("Los Angeles");
        _cityList.Add("Las Vegas");
        _cityList.Add("Philadelphia");
        _cityList.Add("Phoenix");
        _cityList.Add("San Antonio");
        _cityList.Add("San Diego");
        _cityList.Add("Dallas");
        _cityList.Add("San Jose");
        _cityList.Add("San Francisco");
        _cityList.Add("Columbus");
        _cityList.Add("Seattle");
        _cityList.Add("Washington");
        _cityList.Add("Oklahoma City");
        _cityList.Add("New Orleans");
        _cityList.Add("Honolulu");
        _cityList.Add("Virginia Beach");
    }    
}

</string></string></string></string></string>

推荐答案

为了使您的生活更轻松,最好使用跨浏览器兼容的javascript库.我建议使用jQuery和PrototypeJS:
http://prototypejs.org/ [ ^ ]
http://jquery.com/ [ ^ ]
使用这些库,您不必自己做所有艰苦的工作.您可能需要检查哪些浏览器支持哪些版本.

最好的问候,
Manfred
To make life easier for you it would be best to use cross browser compatible javascript libraries. I suggest jQuery and PrototypeJS:
http://prototypejs.org/[^]
http://jquery.com/[^]
Using these libraries you don''t have to do all the hard stuff yourself. You may want to check though which broswers in which versions are supported.

Best Regards,
Manfred


在处理程序ashx的Chrome和Ajax JQuerry调用上,我也遇到了类似的问题.
经过几个小时的搜索,我发现问题出在Chrome和返回响应的方式之间.
只能通过以下方式来结束响应方式:
I am also having similar problems with Chrome and Ajax JQuerry call to the handler ashx.
After several hours of searching, I found that the problem is between Chrome and how the response is returned.
The mode of response must be end completed only by:
context.Response.Flush();
//    context.Response.Close();   //  Chrome problem //
context.Response.End();


特别是不要使用" context.Response.Close()",我已经在那儿读过帖子
它是关闭",会切断触发Chrome中错误的连接.

希望对所有人都有用.

PCMF


Especially do not use "context.Response.Close()" I''ve read there post
It is "Close" which cuts the connection that triggers the error in Chrome.

Hoping that it might be useful to all.

PCMF


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

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