简体   繁体   中英

How to fetch wcf dataservice by jquery?

I am trying to fetch wcf service from jquery. I have written below code but getting error.

jquery code:

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

<%@ 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.

Error: Microsoft JScript runtime error: '$' is undefined

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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