onsubmit with jQuery Ajax - Symfony2 forum
+ Reply to Thread
Results 1 to 7 of 7
  1. #1

    Join Date
    Mar 2012
    Location
    Chennai, India
    Posts
    3

    onsubmit with jQuery Ajax

    In safari browser , i have developed some validation code through jQuery Ajax. while i was use onsubmit method , the ajax code didn't work properly. so i couldn't take value and not complete the validation process.

    pls any one help me for close this issue.

    Thanks in advance.

    Thanks & Regards,
    Naga

  2. #2
    Tobias's Avatar

    Join Date
    Jul 2011
    Posts
    95
    Post us some code or some concrete question. Then I'll do my best to help you.
    Don't reinvent the wheel.
    Tobias

  3. #3

    Join Date
    Mar 2012
    Location
    Chennai, India
    Posts
    3
    Hi Tobias,

    Thanks for quick reply. I was listed some html & script code below of this passage. I think it will be help to you.

    HTML:

    <! DOCTYPE HTML>
    <html>
    <head>
    <script type="text/javascript" src="Script/HealthLogin.js"></script>\
    </head>
    <body >
    <form id="LoginForm" method="post" onsubmit="submitPage()" enctype="multipart/form-data" action="roleProfile.html">
    <td>UserName</td> <td><input type="text" id="txtUser" class="tb8" title="User Name" autofocus></td><td>&nbsp;&nbsp;&nbsp;</td>
    <td>Password</td> <td><input type="password" id="txtPassword" class="tb8" title="Password"></td>
    <!-- <td><img src="Themes/Images/Go.png" id="lgnClick" class="GoIcon" title="Go" /></td> <td><img src="Themes/Images/voice.png" class="IconImgs" title="Voice" onClick="alert('Page Under Constrution')" /></td> -->
    <!-- <td> <input type="submit" value="submit" /> </td> -->
    <td id="tdSubBtn"><input type="submit" value="" style="background-image:url(Images/Go.png); no-repeat center top; width:30px; height:30px; border:0px solid red; position:absolute; top:10px;" /></td>
    </form>
    </body>
    </html>

    Script Code:
    function submitPage()
    {

    getUserName = $("#txtUser").val();
    getPassword = $("#txtPassword").val();

    if( getUserName.length > 0 && getPassword.length > 0)
    {
    $.ajax(
    {
    type: "POST",
    url: "http://www.max360group.com/max360group_demo/HISonMobile.asmx/LoginCheck",
    data: "{'Username':'" + getUserName + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(mgs)
    {

    if(mgs.d != "InValid User!")
    {
    getTimeIndexValue = mgs.d.indexOf('!');
    getTimeValue = mgs.d.substring(0,getTimeIndexValue);
    getUserType = mgs.d.substring(getTimeIndexValue+1,getTimeIndexVa lue+2);

    sessionStorage.setItem('setSessLastLogin', getTimeValue);
    sessionStorage.setItem('setSessUserType', getUserType);

    rolePageCall();
    }

    },
    error: function (mgs)
    {
    alert(mgs.d);
    }
    });

    }

    else
    {
    alert(" Username or Password can not be empty");
    }

    }

    Thanks in Advance.

    Regards,
    Naga

  4. #4
    Tobias's Avatar

    Join Date
    Jul 2011
    Posts
    95
    I see one obvious error. The form is still posted as normal. You have to disable the basic post functionality.
    Make sure the submitPage() return false all the time.

    I'm not sure about you form-tag:
    Code:
     <form id="LoginForm" method="post" onsubmit="submitPage()" enctype="multipart/form-data" action="roleProfile.html">
    Maybe you should rewrite it to:
    Code:
     <form id="LoginForm" method="post" onsubmit="javascript: return submitPage();" enctype="multipart/form-data" action="roleProfile.html">
    Is the page still reloading?
    Don't reinvent the wheel.
    Tobias

  5. #5

    Join Date
    Mar 2012
    Location
    Chennai, India
    Posts
    3
    Thank you for the reply.

    I will the correct the code. Once again thanks for your help.

    Regards,
    Naga

  6. #6

    Join Date
    Apr 2012
    Posts
    1
    Thank you for the posting

  7. #7

    Join Date
    Aug 2013
    Posts
    3
    Hi Technonaga, the Tobias's solution was good enough for fixing your problem? I have one similar and I don't know how to find a solution.
    Thanks in advance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts