duanchuang1935 2016-07-08 06:26
浏览 66

多步骤表单从步骤1到步骤2检索数据

Beginner in jquery ajax. I would like to retrieve datas (this part of the job is done and ok) AND to pass them from step1 to step2 of my form.

My code for the moment is : I've tried to show with #step2 #check-ok the place where I want my datas after phase1 display none and phase2 appear but not working : my datas stay on step1.

   $(".open1").click(function() {
      if (v.form()) {
        var data = {
        'civility'   : jQuery("input[name=civility]:checked", "#to-bc-clt").val(),
        'society'    : jQuery('#society').val(),
        'firstName'  : jQuery('#firstName').val(),
        'lastName'   : jQuery('#lastName').val(),
        'email'      : jQuery('#email').val(),
        };

    jQuery.ajax({
    url : '/mySite/VerifRep/parsers/check.php',
    method : 'POST',
    type    : 'POST',
    data : data,


    success : function(data){
      if (data != 'passed') {
        jQuery('#messages-errors').html(data);
        }  
      if (data == 'passed') {
        $(".frm").hide("fast");
        $("#step2").show("slow");
        $(".open1").css("display","none");
        $(".open2").css("display","inline-block");

         $("#step 2 #check-ok").val(data);
         // Try that way too but not work --> $("#check-ok").html(data);

        }
    },
    error : function(){
        alert('Something wrong.'); }
        });
      }
    });
  • 写回答

1条回答 默认 最新

  • doumie6223 2018-10-20 19:06
    关注

    You can use JSON to store the details locally similar to session of php I also had the same problem I had multiple step form and wanted details of step 1 ( plan choices of member ) and use them in function and calculate result and display it in 3rd step where payment was to be done ( cost the plan chosen by that member )

    Form should have method POST ( if you use GET , replace POST in php file with GET)

    In first step , use JSON like

    var x = document.getElementByName(name_of_textbox_which_has_name);
    var y = document.getElementByName(name_of_textbox_which_has_age);
    var z = document.getElementByName(name_of_textbox_which_has_city);
    
    var val = {name: x, age: y, city: z};
    var toBeSent = JSON.stringify(val);
    window.location = "phpfilename.php?xyzvar=" + toBeSent;
    

    Put this in a function and call it when user clicks on "Next" button ...

    Now , before coming to 2nd step ... In php file ( phpfilename.php ) Remember the variable name was "xyzvar"

    <?php
    $name=$_POST['xyzvar'];
    $data=json_decode($name);
    echo $data->name //  prints x ( name entered in textbox )
    echo $data->age //  prints y ( age entered in textbox )
    echo $data->city //  prints z ( city entered in textbox )
    // instead of echo you can use it anywhere for further coding
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题