How do I execute a PHP query on select option choice using AJAX?

前端 未结 3 1909
暖寄归人
暖寄归人 2020-12-05 09:02

Okay I know this has been answered before (Execute PHP script on same page after selecting a dropdown list option using Ajax or JavaScript) but the answers weren\'t very hel

3条回答
  •  暖寄归人
    2020-12-05 09:36

     var id="1";
     $.ajax({
        type: 'POST',
        url: 'yourphppage',
        dataType: "json",
        data: {
            idofrow:id
        },
        success: function(data) {
            alert(data);
        },
        error: function(data) {
            alert(data);
        }
    });
    

    This is a samle of ajax request you can use this and just change the other fields as need when the query is success you can retrieve that data in the success you can manipulate what data you want to use you can return json,text.

    In your php page you can retrieve the id as

    $id = ($_POST['idofrow']);
    

    you can then you this id to select like this

    SELECT * FROM table where rowid = $id
    

    and you can just echo the result.

    for additional info just check on this documentation

提交回复
热议问题