简体   繁体   中英

passing value to ajax success: function

I have a function that calls a generic handler for some server action and upon completion of the handler I want to pass a message to the ajax success function based on what happened server side.

is it possible to do this and how can I do this?

this is what I have in mind

$(document).on("click", "input[name='chkUserStreaming']", function () {

var prodKeyStream = $("input[name='prodKeyStream']").val();

$.ajax({
    url: 'Handlers/StreamingForUser.ashx',
    data: { 'prodKeyStream': prodKeyStream },
    success: function (data) {

        //here is where I want an alert message based on the value passed from
        //handler

    }

});

here is the handler

public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        bool success;//true or false which I want to pass to the call back
        var prodKeyStream = context.Request["prodKeyStream"].ToString();


        //server side action, from here I want to pass a varaible(message)
        //to ajax success callback             

    }

Thank you

将字符串写入您的processrequest方法中的响应对象:

context.Response.Write(message);

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