开发者

JQUERY, AJAX Request and then loop through the data

Does anyone see anything wrong with the following:

$.ajax({
    url: '/tags/ajax/p开发者_JAVA百科ost-tag/',
    data: { newtaginput : $('#tag-input').val(), customerid : $('#customerid').val()},
    success: function(data) {
        // After posting
        alert(data);
        arr = data.tagsinserted.split(',');
        alert(arr);
        //Loop through
        $.each(arr, function(n, val){
            alert(n + ' ' + val)
        }); 
    }
}, "json"); 

tagsinserted is what's being returned, here is the full response:

{"returnmessage":"The Ajax operation was successful.","tagsinserted":"b7,b4,dog,cat","returncode":"0"}

Thanks


Anurag is right in his comment json needs to be dataType:'json'

also, unless specified, request is "GET" by default, your url suggests it is expecting post data, i.e. type:'post'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜