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.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝