JQuery Validation远程JSFiddle

时间:2014-02-20 13:42:59

标签: javascript jquery ajax validation jquery-validate

我遇到了jquery验证远程和我的表单提交问题。 查看此代码http://jsfiddle.net/35cHS/135/

<form id="fail">
    <label>Documento:</label>
    <input id="numero_documento" maxlength="2" name="numero_documento" maxlength="16" type="text" />
    <input type="submit" value="Próximo" />
</form>

$('document').ready(function () {
    $('#fail').validate({
        rules: {
            numero_documento: {
                required: true
                ,remote: {
                    url: 'http://cep.correiocontrol.com.br/04676090.json',
                    success: function (data) {
                        //console.log('Ok! Continue submit...');
                    }
                }
            }
        }
    });
});

当我插入一个值并单击按钮时,它就可以了。提交被提交。 但如果我取消注释遥控器并再次插入一个值并单击确定没有任何反应。

我希望继续提交表单,因为我只是想进行搜索并返回是或否。

有可能吗?

对不起我的英语我正在努力=)

1 个答案:

答案 0 :(得分:0)

remote有点误导,因为它实际上只意味着another file on your server所以在这种特殊情况下,你不能做一个跨域请求来检索那个json对象,除非你使用带有填充的json 。此刻,CORS正在限制你。而是在服务器上创建一个php文件,例如get_json.php,然后使用

echo file_get_contents('http://cep.correiocontrol.com.br/04676090.json');

服务器不受CORS的限制,除非cep.correiocontrol.com.br上的配置配置为完全拒绝这些请求。