Unable to post variables with jquery post()

后端 未结 2 1857
名媛妹妹
名媛妹妹 2021-01-29 08:29

I am trying to pass variables from a modal form to another page. I declare the variables from the form with the id tags in each selection.

Page reloads to test.php, howe

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 08:58

    It's not clear how are you planning to use this code to pass values from your modal form but there are several problems with your current code:

    1. ; is missing at the end of variable assignment
    2. read values from input fields using val() instead of getting jquery objects of them
    3. use variable names in data object of post method instead of literals ("id", "name")

    Try this to see that variables are passed and echoed in a callback function

    var id = $( "#id" ).val(),
        name = $( "#name" ).val();
    
    $.post("jqtest/test.php", 
           { device_id: id, device_name: name },
           function(data){
                alert(data);
            }
    );
    

提交回复
热议问题