来自html中单页的多个Web服务请求

时间:2014-01-23 04:31:54

标签: php jquery html ajax web-services

我想在单页中提交三个表单。但我坚持一点。 我想在第一张表格中验证手机号码。然后在最终表格提交中使用该手机号码

我已尝试在单个表单中使用此功能,但之后如何发送带有验证移动按钮的发送验证引脚的Web请求。

我有三个这样的表格,

    //First Form Take Mobile Number, web service will send verification Pin as reply to this action
    <form name="PhoneVerification" action="url to phone verification web service" >
    Phone Number: <input type="text" name ="number" id="phone">
    <input type="submit" name ="submit1" id="submit1">Verify Mibile Number</input>
    </form>

//Second Form verifies pin Locally which is sent by first service
    <form name="PinVerification" action="verify pin came from previous web service">
    Verification Pin(Sent on Mobile Number): <input type="text" name ="pin" id="pin">
    <input type="submit" name ="submit2" id="submit2">Verify Pin</input>
    </form>

//Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
    <form action="web service call to complete signup">
    Email: <input type="text" name ="email" id="email">
    Password: <input type="text" name ="pass" id="pass">
    PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
    <input type="submit" name ="submit3" id="submit3">Complete Signup</input>
    </form>

问题是我无法获得电话号码的价值,因为在提交表格后页面会刷新。

我阅读了一些关于使用AJAX的线程,但是如何在这种情况下使用Ajax。 我怎样才能做到这一点。使用AJAX,或使用PHP。

2 个答案:

答案 0 :(得分:2)

    Id must be unique in your html page. In above code id="phone" be present in first to forms. the second form in pinVerfication right but there is an same id = "phone" . please change it and make an another try. third form have also same problem

    //Second Form verifies pin Locally which is sent by first service
        <form name="PinVerification" action="verify pin">
        Verification Pin(Sent on Mobile Number): <input type="text" name ="number" id="pin">
        <input type="submit" name ="submit2" id="submit2">Verify Pin</input>
        </form>

/Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
    <form action="web service call to complete signup">
    Email: <input type="text" name ="email" id="email">
    Password: <input type="text" name ="pass" id="pass">
    PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
    <input type="submit" name ="submit3" id="submit3">Complete Signup</input>
    </form>

答案 1 :(得分:1)

您可以使用cookiessessions来完成此任务。

如果你只想用javascript做,你可以使用cookies。您可以从w3schools

获得最佳参考

您可以使用像php这样的服务器端脚本并使用ajax。 在这种情况下,您可以使用session

cookiessession中的第一个表单提交商店编号。并以另一种形式从cookiesession获取该值,并使用它。

注意:完成所有工作后,请不要忘记删除cookiessession