dton37910 2014-09-10 15:22
浏览 126
已采纳

AJAX调用来调用远程JS函数

I have a slideshow (jQuery Cycle2 plugin) running on a server. The slideshow can be paused and stopped with buttons invoking jQuery functions on the slideshow.

The application is structured as follows: In the index.php I define the slideshow functions (stop, pause, etc.) and an AJAX call within a function that sends a POST to another PHP script to load the slideshow content from the server. So far, this works nicely.

Now, I want to have another script (or maybe Webservice) remoteControl.php that allows me to remote control my slideshow from a third device. So say I run the slideshow on the server and from another site (probably same domain) I call the slideshow functions in the index.php using also AJAX. At the moment this does not work. In the body section of my index.php I put:

if(isset($_POST['action'])){
    $actionOnSlideshow = $_POST['action'];
    echo '<script>'.$actionOnSlideshow.'();</script>';
}
?>

followed by all the other content and scripts for the slideshow. The $actionOnSlideshow variable contains the respective function sent from the AJAX request in the remoteControl.php. Could this relate to the same-origin-policy. The second AJAX call however is from the same domain so this should not be the issue!?

  • 写回答

1条回答 默认 最新

  • duanlachu7344 2014-09-11 03:49
    关注
    1. I'm assuming you don't want to rebuild your app using something like meteor js on the server, which pushes updates to the client. You'd have to rebuild your php pages so I'm just mentioning that for reference.

    2. Websockets is promising but not yet stable enough cross-platform for production.

    3. If you are running nginx and can recompile, you can use the NGiNX_HTTP_Push_Module combined with AJAX Long Polling.

    4. And finally if all else fails, AJAX using good old setTimeout and setInterval will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理