weixin_33676492 2012-12-06 14:21 采纳率: 0%
浏览 158

URL和回调参数

What does the &callback parameter in a URL do? The reason I am asking is because I am running a query with jquery's $.ajax function and when I include &callback=? in the end of the url I get a 400 (bad request) error.

Here is my javascript code:

var energy_query_array = [];


var masterEnergyTable_tableid = '145TOXaanydD63tvgVMmCVH0hei0NXNCEK8ekZBg';
var current_date = 'Jan-12';

var energy_query = 'SELECT * FROM ' + masterEnergyTable_tableid; 

var encoded_energy_query = encodeURIComponent(energy_query);
var energy_url = ['https://www.googleapis.com/fusiontables/v1/query'];
energy_url.push('?sql=' + encoded_energy_query);
energy_url.push('&key=' + apiKey); 
//energy_url.push('&callback=?');
$.ajax({
url: energy_url.join(''),
datatype: 'jsonp',
success: function(data) {
           var name_array = data['columns'];
           var data_array = data['rows'][0];
       for(var i = 1; i < data['columns'].length; i++) {
        energy_query_array[name_array[i]] = data_array[i];
       }
     }
});

console.log(energy_query_array);

I have commented out the line where I add &callback=? to the url because when I leave it in the query returns the error: "message":"Invalid value for parameter callback: ?"

However, earlier in the code I performed a similar query to google fusion tables using the same parameter for callback.

The console.log call at the end of the code displays an empty array to the console.

  • 写回答

3条回答 默认 最新

  • weixin_33701294 2012-12-06 14:24
    关注

    Read about Query Strings

    They start with a ?, and additional parameters get concatnated with &. The ? should never be anywhere but the beginning of the string unless it's encoded.

    The key value pairs then are available to the server, as this is how a standard GET request is performed.

    For example:

    http://myserver.com?name=josh&age=24&state=il

    Your web server is probably choking on the query string somewhere.

    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备