dqly83915 2011-12-15 05:47
浏览 40
已采纳

你如何使用PHP和jquery获取jsonp?

I have this PHP:

$response = 'success';
$response = json_encode($response);
echo $_GET['callback'] . '('.$response.')';

and this jQuery:

$.ajax({url: "/*url*/?invite="+getinvite+"&api="+api, dataType:"jsonp", 
    success: function(response){/*do stuff*/}});

On XAMPP on my laptop it was working great. Then when I put it on my server it gives me this error: Undefined index: callback.

Why is it not letting me set $_GET['callback']? and how would this problem be fixed?

  • 写回答

2条回答 默认 最新

  • dpdbu24262 2011-12-15 06:08
    关注

    You aren't setting a parameter called 'callback' and so it isn't set in the $_GET variables.

    You could fix the error message by doing:

    $callback = "";
    if(array_key_exists('callback', $_GET) == TRUE){
        $callback = $_GET['callback'];
    }
    

    However I don't think you may have misunderstood the .ajax call in jQuery - the javascript function that is called on success is not passed to the server; it is only held inside jQuery.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle
  • ¥15 2024年全国大学生数据分析大赛A题:直播带货与电商产品的大数据分析 问题5. 请设计一份优惠券的投放策略,需要考虑优惠券的数量、优惠券的金额、投放时间段和投放商品种类等因素。求具体的python代码
  • ¥15 有人会搭建生鲜配送自营+平台的管理系统吗
  • ¥15 用matlab写代码
  • ¥30 motoradmin系统的多对多配置
  • ¥15 求组态王串口自定义通信配置方法或代码?
  • ¥15 实验 :UML2.0 结构建模
  • ¥20 用vivado写数字逻辑实验报告撰写,FPGA实验