从javascript的内容页面调用webservice [英] call webservice from content page from javascript

查看:59
本文介绍了从javascript的内容页面调用webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从内容页面调用来自javascript的自动完成web服务.webservice在同一个web应用程序本身。如果我使用一个简单的.aspx页面,它调用webservice并且一切正常。但是只要我应用master页面到它,它根本不起作用。我没有在主页面上放置脚本管理器。所以我想在内容页面本身上使用脚本管理器。

i搜索它并应用以下内容/>


< asp:Content ID =Content1ContentPlaceHolderID =headrunat =server>



< asp:Content ID =Content2ContentPlaceHolderID =ContentPlaceHolder1runat =server>

i want to call a autocomplete webservice from javascript from a content page.webservice is in the same web app itself.if i use a simple .aspx page it calls the webservice and everything works fine.but as soon as i apply master page to it,it doesnt work at all.i have not placed script manager on master page.so i want to use script manager on content page itself.
i have googled for it and applied the following

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">
   </asp:ScriptManager>




<script type="text/javascript">
     $(document).ready(function () {
         SearchText();
     });
     function SearchText() {
         $("#txtSearch").autocomplete({
             source: function (request, response) {
                 $.ajax({
                     type: "POST",
                     contentType: "application/json; charset=utf-8",
                     url: "AutoComplete.asmx/GetAutoCompleteData",
                     data: "{'username':'" + extractLast(request.term) + "'}",
                     dataType: "json",
                     success: function (data) {
                         response(data.d);
                     },
                     error: function (result) {
                         alert("Error");
                     }
                 });
             },
             focus: function () {
                 // prevent value inserted on focus
                 return false;
             },
             select: function (event, ui) {
                 var terms = split(this.value);
                 // remove the current input
                 terms.pop();
                 // add the selected item
                 terms.push(ui.item.value);
                 // add placeholder to get the comma-and-space at the end
                 terms.push("");
                 this.value = terms.join(", ");
                 return false;
             }
         });
         $("#txtSearch").bind("keydown", function (event) {
             if (event.keyCode === $.ui.keyCode.TAB &&
                        $(this).data("autocomplete").menu.active) {
                 event.preventDefault();
             }
         })
         function split(val) {
             return val.split(/,\s*/);
         }
         function extractLast(term) {
             return split(term).pop();
         }
     }</script>
<div class="ui-widget"><label for="tbAuto">Enter UserName: </label>
<asp:TextBox ID="txtSearch" runat="server" Width="300px">
</div>

解决方案

(document).ready(function(){
SearchText();
});
函数SearchText(){
(document).ready(function () { SearchText(); }); function SearchText() {


#txtSearch)。autocomplete({
source:function(request,response){
("#txtSearch").autocomplete({ source: function (request, response) {


.ajax({
type: POST
contentType: application / json; charset = utf-8
url: AutoComplete.asmx / GetAutoCompleteData
data: {'username':' + extractLast(request.term)+ '}
dataType : json
成功:fu nction(data){
response(data.d);
},
错误:函数(结果){
alert( 错误 );
}
});
},
焦点:function(){
// 阻止插入值焦点
返回 false ;
},
选择:function( event ,ui){
var terms = split( this value );
// 删除当前输入
terms.pop();
// 添加所选项目
terms.push(ui.item。 value );
// 添加占位符以获取末尾的逗号和空格
terms.push( );
value = terms。 join );
return false ;
}
});
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "AutoComplete.asmx/GetAutoCompleteData", data: "{'username':'" + extractLast(request.term) + "'}", dataType: "json", success: function (data) { response(data.d); }, error: function (result) { alert("Error"); } }); }, focus: function () { // prevent value inserted on focus return false; }, select: function (event, ui) { var terms = split(this.value); // remove the current input terms.pop(); // add the selected item terms.push(ui.item.value); // add placeholder to get the comma-and-space at the end terms.push(""); this.value = terms.join(", "); return false; } });


这篇关于从javascript的内容页面调用webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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