简体   繁体   English

如何通过jQuery获取WCF数据服务?

[英]How to fetch wcf dataservice by jquery?

I am trying to fetch wcf service from jquery. 我正在尝试从jquery获取wcf服务。 I have written below code but getting error. 我已经写了下面的代码,但出现错误。

jquery code: jQuery代码:

function LoadAutoComplete(method, param) {

    firstIncrement = pageSize + 1;
    $.ajax({
        type: "POST",
        url: "Services/Popup.svc/" + method,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: params,
        processdata: true,
        success: function (data) {

            if (data.PopupData != null) {
                alert(data);
            }
            else {
                //response = null;
                //return response;
            }
        },
        error: function (result) { alert("Error"); }
    });
}

function LoadTest(id) {
    var prm = "<%= this.Sequence %>";
    var params = '"sequence":' + prm;
    method = "GetNotes";

    LoadAutoComplete(method,params);
}

.aspx page .aspx页面

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

<!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">
  <script src="JS/Popup.js" type="text/javascript"></script>
  <script type="text/javascript" language="javascript">
    LoadAutoComplete("GetNotes","<%= this.Sequence %>");
  </script>
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  </div>
  </form>
</body>
</html>

GetNotes is my method name which i have written in Business logic. GetNotes是我在业务逻辑中编写的方法名称。

Error: Microsoft JScript runtime error: '$' is undefined 错误:Microsoft JScript运行时错误:'$'未定义

您需要包括jQuery,在其他脚本之上添加以下脚本标记:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM