doudui6756
doudui6756
2015-02-20 03:21

获取文本框值在同一页面上但不同的php文件

已采纳

I have this main page that loads another php file on onchange event of the dropdown. I use this to load the page:

function get_value(){
    if($("#dropdwn").val()=="0"){
        //load nothing
    }else{
        $('#txtval').val($("#dropdown").val());
        $('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
        $('#load_page').load('load_xml.php');
    }
}

For now I put the value of dropdown on the textbox but will also try to get the value of dropdown. The problem is on the second php file that loads on the main page. I can't get the value of $txtval=$_POST['txtval'] when I use this. I will need the value for if else condition.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dqq9695 dqq9695 6年前

    First you need to sent the parameter to the resource load_xml.php.

    function get_value() {
        if ($("#dropdwn").val() == "0") {
            //load nothing
        } else {
            var val = $("#dropdown").val();
            $('#txtval').val(val);
            $('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
            $('#load_page').load('load_xml.php?txtval=' + val);
        }
    }
    

    The the load method uses a GET request, not a POST method.

    $txtval=$_GET['txtval']
    

    If you want to sent a POST method, then use the syntax

    function get_value() {
        if ($("#dropdwn").val() == "0") {
            //load nothing
        } else {
            var val = $("#dropdown").val();
            $('#txtval').val(val);
            $('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
            $('#load_page').load('load_xml.php?', {
                txtval: val
            });
        }
    }
    

    then

    $txtval=$_POST['txtval']
    
    点赞 评论 复制链接分享