Invalid Label - jQuery Ajax/Json request

隐身守侯 提交于 2020-01-05 06:40:34

问题


I've been pulling my hair out over this;

function status_update( token, loader ){
$("#status-submit").bind( 'click', function(){
    try{
        $("#status-feed-result").html( loader );
        $("#status-input").attr("disabled", "disabled");
        var status_input = $("#status-input").val();
        $.ajax({ 
            type: 'POST', url: './', data: 'token=' + token + '&refresh=true&status-input=' + status_input + '&aj=true', cache: false, timeout: 5000, datatype: 'json',
            error: function(){ $("#status-input").removeAttr('disabled'); }, 
            success: function(html){ 
                auth(html); 
                $("#status-input").removeAttr('disabled'); 
                $("#status-input").val(''); 
                var JSON = eval(html);

                alert(JSON.PROFILE_STATUS); 

                //$(".status-p").html( JSON.PROFILE_STATUS );
                //$(".time").html( JSON.PROFILE_STATUS_TIME );
            }                           
        });
    }catch(err){}
    return false;                                           
});
}

I keep getting an error invalid label, what does this mean and how can I prevent from happening. Any help much appreciated.


回答1:


Sounds like it could be related to a jQuery repeat ajax call bug listed here: jQuery Bug #8398

It turns out that jQuery 1.5 is modifying subsequent ajax calls for json to jsonp which leads to this error.

I fixed it by following one of the workarounds suggested in the bug change history and placing the following code somewhere before my ajax calls are made:

$.ajaxSetup({
   jsonp: null,
   jsonpCallback: null
});

Should fix any problems for other ajax requests too.




回答2:


I got this error when I wasn't specifying the success() function correctly. Try doing the following code where data is whatever information your passing back:

success : function(data,status,response){

EDIT:

My error was actually there because I was using a plug-in called validate.js. If you're using this plug-in and including validate.pack.js, this could be your problem.



来源:https://stackoverflow.com/questions/2606155/invalid-label-jquery-ajax-json-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!