Ajax自动填充问题 [英] Ajax Autocomplete trouble

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

问题描述

我在页面上遇到自动填充问题。设置很复杂:

FrameworkMasterPage

ApplicationMasterPage

MyContentPage



最初, FrameworkMasterPage保存了asp:UpdatePanel中的所有内容,但我尝试删除它只是为了检查,即使没有updatepanel它也不起作用。



我调用PageMethod,以下签名:

I'm having trouble with the autocomplete on the page. The setup is complicated:
FrameworkMasterPage
ApplicationMasterPage
MyContentPage

Initially, FrameworkMasterPage holds everything in asp:UpdatePanel, but I've tried removing it just to check, it doesn't work even without updatepanel.

I call PageMethod, with the following signature:

<System.Web.Services.WebMethod()> _
   Public Shared Function GetPrimatelj(prefixText As String, count As Integer) As String()
     Dim tl As New List(Of String)
        tl.Add("one")
        tl.Add("two")
        tl.Add("onu") ' so I can check that "on" return two selections

        Return tl.ToArray
End Function





方法执行成功,但结果是整页渲染而不是方法结果。我得到自动完成下拉列表,但它包含一个在另一个下面

D

o

c

t
$ b $

p
$ b $等等......整页翻译。



我试过直接调用PageMethod代理...相同的结果。我已经尝试了两个AjaxToolkit AutoCompleteExtender(因此,上面的签名)和jQuery Ajax调用



相同的结果。是的,之前我做过自动完成,然后一次:)。



这是(基础,由于缓存处理,代码更多,但这是关键部分)我的ajax电话





The method is executed successfully, but the result is full page rendering instead of method result. I get autocomplete dropdown, but it contains one under the other
D
o
c
t
y
p
e etc...whole page rendering letter by letter.

I've tried calling directly PageMethod proxy...same result. I've tried both AjaxToolkit AutoCompleteExtender (thus, the signature above) and jQuery Ajax call

Same result. Yes, I did autocomplete before, more then once :).

This is (base, there is more code due to cache handling, but this is the critical part) my ajax call

$.ajax({
                           url: "AjaxController.aspx/GetPrimatelj",
                           data: "{ 'term': '" + request.term + "' }",
                           dataType: "json",
                           type: "POST",
                           contentType: "application/json; charset=utf-8",
                           dataFilter: function (data) { return data; },
                           success: function (data) {
                               oldterm = request.term;
                               cache[request.term] = data.d;
                               response($.map(data.d, function (item) {
                                   return {
                                       value: item
                                   }
                               }))
                           },
                           error: function (result, status, error) {
                               console.log(status + " - " + error);
                           }
                       });





帮助?



Help?

推荐答案

.ajax({
url: AjaxController.aspx / GetPrimatelj
data: {'term':' + request.term + '}
dataType: json
类型: POST
contentType: application / json; charset = utf-8
dataFilter: function (data){ return data;},
成功: function (data){
oldterm = request.term;
cache [request.term] = data.d;
响应(
.ajax({ url: "AjaxController.aspx/GetPrimatelj", data: "{ 'term': '" + request.term + "' }", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function (data) { return data; }, success: function (data) { oldterm = request.term; cache[request.term] = data.d; response(


.map(data.d, function (item){
返回 {
value:item
}
}))
},
错误: function (结果,状态,错误){
console .log(status + - +错误);
}
});
.map(data.d, function (item) { return { value: item } })) }, error: function (result, status, error) { console.log(status + " - " + error); } });





帮助?



Help?


你能分享你想要实现的目标吗? ? Javascript URL看起来像MVC模式,但您使用的是更新面板,它是传统ASP Web应用程序的一部分。



您是否从任何一个调用.Ajax方法主要新闻发布会。如果是这样,如果函数写在同一页面上,则需要只有函数名,那里不需要页面名。

在控制台的Chrome开发人员工具(F12)中,您可以看到是否收到4XX错误。如果没有,那么你的网址没问题。



通过简单的改变确认一下并告诉我。



- Maheswaran.S
Can you share what you were trying to achieve here ? The Javascript URL seems like MVC pattern, But you have used Update panel that is part of legacy ASP web application.

Are you calling the .Ajax method from any of the Key press event. if so, if the function written on the same page , you need to have only function name , it does not required page name there.
In Chrome developer tool (F12) in the console you can see whether you getting 4XX Error or not. If not then your URL is fine.

Confirm this with by putting simple alter and let me know.

- Maheswaran.S


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

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