dongyan5641 2013-12-07 08:11
浏览 84

如何使用GET将值从ajax传递给php

I have this script in ajax and is used to pass the value chosen by the user in the combo box to php. This also handles the submit button.

AJAX:

<script>    
function loadXMLDoc(usertype) {
    var value = $('#usertype').val();
    var page='checksignup.php?usertype='+usertype;
    document.location.href=page;
}


$( "#register_Chairperson" ).submit(function( event ) {
  var usertype = $('#usertype').val();
  alert(usertype);
  loadXMLDoc(usertype);
  event.preventDefault();
});
</script>

And I'm using this php code to get the value pass by ajax. But my problem is that nothing happens. My address became only like this: http://localhost/civil-engineering-dept/checksignup.php?usertype=1. It did not continue in checking for the form for signing up. What do you think is the problem?

PHP:

$user = $_GET["usertype"];
  • 写回答

2条回答 默认 最新

  • duanshan1856 2013-12-07 08:13
    关注

    And I'm using this php code to get the value pass by ajax.

    That's not ajax, it looks like an attempt to load the XML in the browser window. To actually do that, change document to window and lose the href.

    window.location=page;
    

    To actually use ajax, you'd use $.ajax or $.get (since you're trying to do a GET); something like this:

    $.get(page)
        .done(function(xml) {
            // Worked, do something with the XML
        })
        .fail(function() {
            // Failed, show/handle the error
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭