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