javascriptphpjqueryjquery-easyui

How to submit data in using easyui form


In my project, I use easyui form which id is ff.

And I want to check the data before submit form. So I use onSubmit in form method.

But I cannot accept data from oat.php, the method alert(data) in success can not display "Your name".

Perhaps jquery.form.js is the reason, but i am not sure.

Here is the head code:

<link rel="stylesheet" type="text/css" href="jsui/easyui-1.5.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jsui/easyui-1.5.3/themes/icon.css">
<script type="text/javascript" src="jsui/easyui-1.5.3/jquery.min.js"></script>
<script type="text/javascript" src="jsui/easyui-1.5.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>

Here js code:

 <script>
 function submitForm(){
  $('#ff').form('submit',{
        url:oat.php,
        onSubmit:function(){
            return $(this).form('enableValidation').form('validate');
            },
        success:function(data){
            alert(data)
            }
        });
}
function clearForm(){
    $('#ff').form('clear');
}
</script>

Here is html code:

<form id="ff" class="easyui-form" method="post" data-options="novalidate:true"  enctype='multipart/form-data'>
        <table cellpadding="5">
            <tr>
                <td>announceTitle:</td>
                <td><input class="easyui-textbox" type="text" name="annTitle" data-options="required:true,multiline:true" style="height:60px"></input></td>
            </tr>
        </table>
        <div class="attFile" id="attFileId">
        <div class="upBtDiv"><label style="color:green">attfile:</label><input type="file" id="fulId" name="mypic"></div>
        <div class="ulfDiv" id="ulfId1"></div>
    </div>
     <div style="text-align:center;padding:5px">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">submit</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">clear</a>
    </div>
    </form>

Here is oat.php code:

<?php
echo "Your Name";
?>

I don't know how? who can help me?


Solution

  • In your code oat.php treated as a variable, you should add quotes so JS would treat it as a string value.

     $('#ff').form('submit',{
            url: 'oat.php', //added quotes.
            onSubmit:function(){
                return $(this).form('enableValidation').form('validate');
                },...