0

我正在尝试使用 JQuery 调用 ASP.NET PageMethod 但没有得到任何东西。我当然错过了一些简单的东西,但由于我是 jQuery 的新手,所以我无法弄清楚。GetJsonEspaces() 没有按预期工作!请问有人能帮我解决这个问题吗?

我的 HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script src="js/BiddyScript.js" type="text/javascript"></script>

<div class="boxCanvas">
    <canvas id="myCanvas" width="800" height="600">
      <p>Your browser does not support the canvas element.</p>
    </canvas>
</div>

JavaScript:

var canvas;
var context;

function drawText(text, x, y) {
    context.font = '10pt Helvetica';
    context.fillText(text, x, y);
}

//will be called back!!
function drawBiddies(biddies) {
    var y = 50;
    for (var i = 0; i < biddies.count; i++) {
        var biddy = biddies[i];
        drawText(20, y, biddy.ID + " " + biddy.Libelle);
        y += 20;
    }
}

// A function that takes two parameters, the last one a callback function
function grabBiddies(options, callback) {
    //allUserData.push(options);
    callback(options);
}

//GET DATA FROM CODEBEHIND!!
function GetJsonEspaces() {
    $.ajax({
        type: "POST",
        url: "BiddyCanvas.aspx/GetEspaces",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            grabBiddies (response.d, drawBiddies);
        },
        error: function (data) {

            alert("Could not complete process !");

        }
    });
}

window.onload = function () {
    //grab the context!!
    canvas = $('#myCanvas')[0];
    context = canvas.getContext('2d');

    context.beginPath();                                      //This initiates the border
    context.rect(1, 1, canvas.width - 1, canvas.height - 1);
    context.fillStyle = "#fcfc00";
    context.fill();
    context.lineWidth = 1;                                     //This sets the width of the border
    context.strokeStyle = "#000000";      //This sets the color of the border
    context.stroke();

    //récupérer les données et dessiner!!
    GetJsonEspaces();
}

我的代码隐藏

using System.Web.Services;

        [WebMethod]
        public static string GetEspaces()
        {
            List<BIDDY> oList = GetListEspaces();
            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string jsonEspaces = oSerializer.Serialize(oList);

            return jsonEspaces;
        }
        ...

谢谢 !!

4

0 回答 0