jeudi 26 novembre 2015

value of a variable reusing in JavaScript

I have following controllers

[HttpPost]
public JsonResult CreateDirectory(string product_ID , string type)
{
   .......

 return Json("OK");

}

[HttpPost]
public ContentResult UploadFiles(string folderid, string foldertype)
{
  .........
}

and using following script I'm trying to call and pass parameters to CreateDirectory controller method and UploadFiles controller method

<script type="text/javascript">

    var productid = "sample";

    $('#idd').click(function () {

        $.ajax({
            url: '@Url.Action("CreateDirectory", "Home")',
            data: { product_ID: $('#Product_ID').val(), type: "type1" },
            type: "POST",
            dataType: "json",            
            error: function (response) {
                alert(response.responseText);
            },
            success: function (response) {
                if (response === 'OK')
                {
                    productid = $('#Product_ID').val();
                    alert(productid)
                }
                else
                    alert("errro");
            }
        });
    });  

  $("#idd").fileinput({
        type: 'POST',
        cache: false,
        uploadUrl: '@Url.Action("UploadFiles", "Home")',
        enctype: 'multipart/form-data',
        overwriteInitial: true,
        uploadExtraData: { folderid : productid , foldertype : "type1" },            

    });   

</script> 

Issue:

I'm assigning new value for var productid in click JavaScript event of above script.

like this productid = $('#Product_ID').val();

then I try to reuse that newly assigned value for productid reuse/reassign in fileinput JavaScript event

like this folderid : productid

but I cannot see newly assigned value for folderid , when Its calling to UploadFiles method I can see folderid is value is sample

Aucun commentaire:

Enregistrer un commentaire