AJAX请求不发送validate()数据

I want to receive the validate function output in my above PHP code. Except my AJAX, all things are working. Can anyone help me correct the problem?

$(document).ready(function(){
    $("#d").click(function(){
        validate();
    })

    function validate() { 
        var x;
        var text;
        var y, senddata;

        x = document.getElementById('t').value;
        y = x.length;

        if (isNaN(x) || y < 10 || y > 10) {
            document.getElementById('t').style.backgroundColor = "red";
        }
        // start AJAX in else case to receive validate data
        else {
            $.ajax({
                url: 'json.php',
                type: "POST",
                dataType:'json',
                data: ({ phone: x }),
                success: function(response){
                    alert ("success !");
                },
                error: function(response){
                    alert("fail!");
                }
            }); 
        }
    }
});

Need to make changes in config to set flag for CORS calls ...

<httpProtocol>
    <customHeaders>
        <!-- Enable Cross Domain AJAX calls -->
        <remove name="Access-Control-Allow-Origin" />
        <add name="Access-Control-Allow-Origin" value="*" />
    </customHeaders>
</httpProtocol>

Also for the AJAX to work please change the condition to go in "else" part

complete with the help of .action in js method and without use of ajax

function datasend(send1,send2)
{
    senddata=send1+send2;
    document.forms["reg"].action="ajax.php?"+senddata;
    //document.forms["reg"].submit();

}