dongzai3139 2014-07-24 11:47
浏览 38

在HTTPS上调用jQuery Ajax

I have a form that takes three steps to fill it. At each of these steps you fill some info, click "Next" and then see either errors you have to fix in order to get to the next step or if there are no errors it takes you to the next step (change "display" to "block" in CSS).

At first step it uses $.ajax() to call file lib/ajax.php which returns some results in JSON that matter a lot to filling the rest of the form. The thing is this works locally on my http://my.dev address, but live on https://something.example.com it does not.

Where should I first try looking to go about it? What are the most common workarounds on this?

Both lib/ajax.php and the index.php file (that has the jQuery call) are on the same domain (https://something.example.com) so we are not talking about cross-domain calls.

Here's some of the code.

$.ajax({
   type: 'GET',
   url: 'lib/ajax.php', 
   async: false,
   data: {id: id}, 
   dataType: 'json', // what type of data do we expect back from the server
   }).done(function(data){
       // do stuff with data
});

and the lib/ajax.php

//stuff with db and retrieving row by id
header('Content-type: application/json');

echo json_encode($result);

That's pretty much it. It doesn't work when I place it on live HTTPS server.

  • 写回答

2条回答 默认 最新

  • douzhuan1169 2014-07-24 11:58
    关注

    In https i think you must change the dataType: 'json' to dataType: 'jsonp'

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作