سؤال

I know some similar questions are also available, but they doesn't help me. I am doing it in Scala Play Framework. I am posting my code below:

var saveNameRequest;    
function saveName(){
        if(!saveNameRequest){   
        saveNameRequest=$.ajax({
            type:"POST",                
            url:"edit?editType=saveName",
            data: $("#nameForm").serialize(),
            complete:function(){saveNameRequest=false},
            success: function(data){
                alert($("#nameForm").serialize())
            }//end success
          });
    }
}

Form serialization is not working, and an empty string is being printed. nothing is going through post, please help

<form method="POST" name="nameForm" id="nameForm">
        <tr>
            <td><font color=#3b5999>First Name:</font></td>
            <td><input type="text" name="fname" id="fname" value="@fName"></td>
        </tr>
        <tr>
            <td><font color=#3b5999>Middle Name:</font></td>
            <td><input type="text" placeholder="optional" name="mname" id="mname" value="@mName" ></td>
        </tr>
        <tr>
            <td><font color=#3b5999>Last Name:</font></td>
            <td><input type="text" name="lname" id="lname" value="@lName"></td>
        </tr>

        <tr>
            <td></td>
            <td><input name="save" id="save" type="button" value="save" onClick="saveName()"></td>
        </tr>
    </form>
هل كانت مفيدة؟

المحلول

i found form serialization does not work with facebox in scala 2.10 we have to send data of all fields,it is the only solution that i got,

data:{
"fname":document.getElementById("fname").value,
"mname":document.getElement‌​ById("mname").value,
"lname":document.getElementById("lname").value
}

نصائح أخرى

You have not closed your saveName() function. Try after closing it. Also, make sure saveName() is outside document.ready().

Add a key to ajax data parameter to send the serialized string like below:

data: { formData: $("#nameForm").serialize() },

Edited the fiddle and it seems to work

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top