Passing value to ajaxform data

jquery

Solution

You are missing a comma after the data property.

Try this:

(function () {
    var value1 = "dynamic_value1";
    var value2 = "dynamic_value2";
    $('.dummyForm1').ajaxForm({
        data: {
            key1: value1,
            key2: value2
        }, //You were missing this comma.
        complete: function (xhr) {
            txt = xhr.responseText;
            alert(txt);
        }
    });
})();

Problem

I want to pass the value of the variable to ajaxForm data. ``` value1 = "dynamic_value1"; value2 = "dynamic_value2"; $('form').ajaxForm({ data: { key1: value1, key2: value2 } }); ``` Expecting something like: ``` date:{Key1:"dynamic_value1", Key2:"dynamic_value2"} ``` So in php i can access like ``` echo $_POST['key1']; ``` ====================== COMPLETE script ``` <script src="../../bin/addons/jquery-1.7.2.js"></script> <script src="../../bin/addons/jquery.form.js"></script> <script> // jQuery Form-plugin (function() { var value1 = "dynamic_value1"; var value2 = "dynamic_value2"; $('.dummyForm1').ajaxForm({ data:{ key1: value1, key2: value2 } complete: function(xhr) { txt = xhr.responseText; alert(txt); } }); })(); </script> <form class="dummyForm1" action="form-php.php" method="post"> <input type="submit" value="Hit!" /> </form> ``` form-php.php ``` <? echo "Key1 value:". $_POST['key1']; ?> ```

Original source