Вопрос

I have JavaScript of ajax uploader as below;

$(document).ready(function(){
var qwerty = $('#qwerty').val();

$('#demo1').ajaxupload({
  url:'upload.php',
  remotePath: qwerty,
  maxConnections:1,
  finish:function(files)
  {
    alert('uploaded');
  },

});
});

var qwerty is the value of a text input having default value="". The field is blank when page loads. The text inside is set as the upload directory of the uploader. But it return null even if I enter some text inside. When I reload the page, the text I enter previously remain there and this time, the text is taken and passed into variable. Again if I change the text, the data passed is the text which remained in the input field and not the one I entered now. How can I always pass the current value of input field into the variable?

Это было полезно?

Решение

You define your ajaxupload when document is ready. After changes in your input nothing has happened, because your ajaxupload uses previous version of your input value.
You can reinitialize ajaxupload after changing textbox value.

   $(document).ready(function(){

   //Initializing when document is ready
   InitializeAjaxUpload();

    $("#qwerty").change(function () {
   //Initializing after input value changes
     InitializeAjaxUpload();
    });
    });

function InitializeAjaxUpload()
{
$('#demo1').ajaxupload({
              url:'upload.php',
              remotePath: $('#qwerty').val(),
              maxConnections:1,
              finish:function(files)
              {
                alert('uploaded');
              }

    });
}

I didn't tested this, but you need something like this. Try it :)

Другие советы

$(document).ready(function(){ means when page loads and all document elements ready. And it called once after page load. At that time your input value is empty so it doesnt matter you type after. You need event listener to get data from input text.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top