dongpenggan6812 2016-06-22 22:27
浏览 517

在jsonp请求上始终获取错误404

I ran into an issue while trying to retrieve some jsonp data from another Host. That's my setup:

Client on 192.168.2.107 running on Raspbian

Host on 192.168.2.109 running apache2 on raspbian

Client is able to get the web Page pump.php from Host via Web Browser.

Code on Client:

$.ajax({
   url: 'http://192.168.2.109/pump.php',
   dataType: 'jsonp',
   success:function(result)        {
             console.log(result);
           },
   error:function (xhr, ajaxOptions, thrownError) { 
            console.log(xhr);
            alert(thrownError + xhr.status);
         }
});

Code on server (pump.php):

header("Content-Type: application/json");
echo "myCall({foo:'bar'});";

I always get a 404 response from the host. Though I'm completely out of ideas what's wrong with my code or something else or even how I should try to troubleshoot this, any help is higly appreciated! Thanks in advance.

[EDIT] Forgot to mention that myCall() is specified in the client as well:

function myCall(data) {
  console.log(data);
}
  • 写回答

1条回答 默认 最新

  • doumao6048 2016-06-22 22:48
    关注

    You may need to allow your ip on the host php page:

    header('Access-Control-Allow-Origin: http://192.168.2.107');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测