weixin_33749242 2016-07-27 05:53 采纳率: 0%
浏览 8

Ajax-网址参数与数据

In JQuery Ajax calls, which of the below is recommended? I know both are similar but is there an obvious advantage between these two?

Ajax call with URL Paramater.

$.ajax({
url: 'test.php?uAction=action&uType=type',
    dataType: 'json',
    success: function(data, status){
            $.each(data, function(i,item){
                });
            },
    error: function(){
            output.text('There was an error loading the data.');
        }
    });

or Ajax call with parameter arranged in object

$.ajax({
    url: 'test.php',
    dataType: 'json',
    data: {
        uAction: 'action',
        uType: 'type'
    },
    success: function(data, status){
            $.each(data, function(i,item){

                });
            },
    error: function(){
            output.text('There was an error loading the data.');
        }
    });
  • 写回答

1条回答 默认 最新

  • weixin_33709219 2016-07-27 06:04
    关注

    if you are making url in ajax call like:

    url: 'test.php?uAction=action&uType=type',
    

    Its type is get and you have to deal with the url encoding mechanism to avoid spaces and other characters. In second approach you don't have to worry about URL encoding keys and values.

    评论

报告相同问题?