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 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教