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.

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失