使用jquery将数据从服务器自动填充到文本框 [英] Autopopulating data from the server to a textbox using jquery

查看:59
本文介绍了使用jquery将数据从服务器自动填充到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在开发一个MVC应用程序.net。



我有一个名为Products的文本框。我必须使用jquery和ajax从服务器的列表中自动提供文本框



这是代码:

@ Html.TextBoxFor( model => model.Products,new {@id =Products})

在这个文本框中,我需要通过ajax调用控制器的动作并获取数据。

$('#Products).autocomplete()

{

alert('kl');

AutoCompleteDetails()< br $>
}



函数AutoCompleteDetails()

{

var url ='@ Url.Action(搜索,学生)';

href = url;



$ .ajax({

url:href,

dataType:json,

数据:AutoDetails,

类型:POST,

上下文:这个,

成功:功能(数据){



}

在页面加载时,控件正在点击学生控制器的搜索操作,我有两个在这里:

1.

在页面加载时,点击搜索操作后我将模型值绑定回页面,但这些值不会被视为下拉列表文本框中的建议称为产品



2.

页面加载后,当我输入KL并标出动作学生控制器的搜索没有被调用。





有什么建议吗?

am developing a MVC application .net.

I have a textbox called "Products". I have to autopoulate the textbox with the list from the server using jquery and ajax

Here is the code:
@Html.TextBoxFor(model=>model.Products,new {@id = "Products"})
In this textbox ,I need to call an action of a controller by ajax and get the data.
$('#Products).autocomplete()
{
alert('kl');
AutoCompleteDetails()
}

function AutoCompleteDetails()
{
var url = '@Url.Action("Search", "Student")';
href = url;

$.ajax({
url: href,
dataType: "json",
data: AutoDetails,
type: "POST",
context: this,
success: function (data) {

}
On the page load, the control is hitting Search action of Student controller, I have two doubts here:
1.
On page load, after hitting "Search" action I am binding the model values back to the page but these values are not seen as dropdown as suggestions in the textbox called "Products"

2.
After the page load, when I type "KL" and tab out the action "Search" of "Student" controller is not getting called.


Any suggestions?

推荐答案

('#Products).autocomplete()

{

alert('kl');

AutoCompleteDetails( )

}



函数AutoCompleteDetails()

{

var url = '@ Url.Action(搜索,学生)';

href = url;


('#Products).autocomplete()
{
alert('kl');
AutoCompleteDetails()
}

function AutoCompleteDetails()
{
var url = '@Url.Action("Search", "Student")';
href = url;


.ajax({

url:href,

dataType:json,

数据:AutoDetails,

类型:POST,

上下文:这个,

成功:功能(数据){



}

在页面加载时,控件正在点击学生控制器的搜索动作,我有两个疑问:

1.

在页面加载时,点击搜索动作后我将模型值绑定回页面,但这些值不被视为下拉列表,因为文本框中的建议称为产品



2.

页面加载后,当我输入KL并标注出学生控制器的搜索动作时没有被调用。





任何建议?
.ajax({
url: href,
dataType: "json",
data: AutoDetails,
type: "POST",
context: this,
success: function (data) {

}
On the page load, the control is hitting Search action of Student controller, I have two doubts here:
1.
On page load, after hitting "Search" action I am binding the model values back to the page but these values are not seen as dropdown as suggestions in the textbox called "Products"

2.
After the page load, when I type "KL" and tab out the action "Search" of "Student" controller is not getting called.


Any suggestions?


我认为你的javascript代码无法成功调用控制器方法。尝试在Ajax调用中使用FireBug.Put断点调试它。检查它是否完全执行并看到控制台窗口,如果它成功请求服务器。如果它没有尝试纠正您的Ajax调用,无论它在哪里。我认为你的数据有问题: AutoDetails。请正确检查。调试后再次运行项目。希望这能帮助您解决问题.Thanx ...
I think somewhere your javascript code fails to successfully call controller method.Try to debug it using FireBug.Put breakpoint in your Ajax call.Inspect whether or not it is executed fully and see console window if it is making a request to server successfully.If not try to rectify your Ajax call wherever it breaks.I think there is a problem in your "data: AutoDetails".Please check it properly.After debugging run the project again.Hopefully this will help you in resolving your problem.Thanx...


这篇关于使用jquery将数据从服务器自动填充到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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