Using href in jquery with get method

i´m learning jquery and i have a question.

On html, when i want to pass variables by get, i write:

$subject=$_GET['subject'];

$id_user=$_GET['id_user'];

$id_pupil=$_GET['id_pupil'];

<a href='process.php?subject=".$subject."&& id_user=".$id_user." && id_pupil=".$id_pupil."'>Add</a>

But i want to do it on Jquery. My idea is:

I have this part of code:

while ($row = mysql_fetch_array($result))
{
    echo "<tr><form action='update_marks.php' method='post'>
        <td><input type='text' name='mark' value='".$row['mark']."'></td>
        <td>".$row['date']."</td>
        <td><input type='submit' value='Update'></td>
        <input type='hidden' name='id_mark' id='id_mark' value='".$row['id_mark']."'>
        <input type='hidden' name='subject' id='subject' value='".$subject."'>
        <input type='hidden' name='id_user' id='id_user' value='".$id_user."'>
        <input type='hidden' name='id_pupil' id='id_pupil' value='".$id_pupil."'>
        </form>
    </tr>";
    echo "<br>";

}
echo "</table>";
echo "<input type='button' id='add' value='Add row' />";

And i would like to add rows in the table on Jquery:

$(document).ready(function(){
    var subj=$('#subject').val();
    var id_us=$('#id_user').val();
    var id_pup=$('#id_pupil').val();

    $("#add").on('click', function(){
        $('#table > tbody:last').after("<tr><td><input type='text' name='mark' value=''></td><td></td><td><a href='add_mark.php?subject=subj && id_user=id_us && id_pupil=id_pup'>Add row</a></td></tr>");


});

I think I understand what you're trying to do. In javascript strings and concatenation are a little different.

Try changing this line:

$('#table > tbody:last').after("<tr><td><input type='text' name='mark' value=''></td><td></td><td><a href='add_mark.php?subject=subj && id_user=id_us && id_pupil=id_pup'>Add row</a></td></tr>");

To:

$('#table > tbody:last').after("<tr><td><input type='text' name='mark' value=''></td><td></td><td><a href='add_mark.php?subject="+subj+" && id_user="+id_us+" && id_pupil="+id_pup+"'>Add row</a></td></tr>");
链接地址: http://www.djcxy.com/p/83490.html

上一篇: laravel 5.4:如何将javascript值传递给控制器​​以更新数据

下一篇: 在jquery中使用href和get方法