Linked Questions

Popular Questions

Getting Ajax variable after success parameter

Asked by At

Here's my Ajax code:

       $("#generateImage").click(function () {
        var url = $(this).data('url');
       var currentUrl =window.location.href;
        $.ajax({
            type: "post",
            contentType: "application/json; charset=utf-8",
            url: url,
            data: "{'urlVar':'"+ currentUrl +"','mywidth':'250','myheight':'480'}",
            success: function (response) {
                if (response != null && response.success) {
                    alert("Success");
                  window.location = '@Url.Action("GetData", "MyController", new { urlVar = currentUrl })';
                } else {

                    alert("Failed");

                }
            },

        });

In this part of code:

new { urlVar = currentUrl })';

currentUrl says:

Does not exist in the current context;

My Question is: How to make currentUrl to be valid on that particular location?

Otherwise there's no error on data: part? data: "{'urlVar':'"+ currentUrl

Related Questions