Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从javascript的内容页调用webservice_Javascript_Jquery_Asp.net - Fatal编程技术网

从javascript的内容页调用webservice

从javascript的内容页调用webservice,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我想从内容页从javascript调用自动完成web服务。web服务本身也在同一个web应用程序中。如果我使用简单的.aspx页面,它会调用web服务,一切正常。但一旦我对其应用母版页,它根本不起作用。我还没有把脚本管理器放在母版页上。所以我想在内容页上使用脚本管理器。 我在谷歌上搜索了它,并应用了以下内容 <script type="text/javascript"> $(document).ready(function () { SearchText(); });

我想从内容页从javascript调用自动完成web服务。web服务本身也在同一个web应用程序中。如果我使用简单的.aspx页面,它会调用web服务,一切正常。但一旦我对其应用母版页,它根本不起作用。我还没有把脚本管理器放在母版页上。所以我想在内容页上使用脚本管理器。 我在谷歌上搜索了它,并应用了以下内容

<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");
                 }
             });
         }
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</asp:Content>

$(文档).ready(函数(){
SearchText();
});
函数SearchText(){
$(“#txtSearch”).autocomplete({
来源:功能(请求、响应){
$.ajax({
类型:“POST”,
contentType:“应用程序/json;字符集=utf-8”,
url:“AutoComplete.asmx/GetAutoCompleteData”,
数据:“{'username':'”+extractLast(request.term)+“}”,
数据类型:“json”,
成功:功能(数据){
答复(数据d);
},
错误:函数(结果){
警报(“错误”);
}
});
}

尝试使用RegisterClient ScriptBlock在Page_Load事件中注册脚本。

打开浏览器控制台,在页面上运行
$(“#txtSearch”)
是否得到结果或空数组?一旦使用ScriptManager,尝试使用pagemethods。
<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");
                 }
             });
         }
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</asp:Content>