duanlipeng4136 2014-02-16 23:25
浏览 16
已采纳

使用后续php段落中脚本返回的var

Presently,

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
    $.get("http://[somewebsite]", function (response) {
       $("#somevalue").html(response.somevalue);
    }, "jsonp");
</script>

up in the body of the source returns a somevalue variable that is then used like this within the page:

<div id="somevalue"></div>

and the underlying value is successfully printed out. But down below further in the source I have some PHP coding that I would like to employ that variable in. If in that later PHP coding I want to take <div id="somevalue"></div> (merely writing somevalue just outputs string literal "somevalue" in the html), and assign the value to n for use inside the PHP, how is such an instruction written? Thanks for any help.

  • 写回答

2条回答 默认 最新

  • doukun5339 2014-02-17 00:02
    关注

    I would load that PHP part later via an Ajax request as well. In this way you can pass the 'somevalue' as a parameter (GET or POST) and you can process it on the server-side.

    $.get("http://[somewebsite]", function (response) {
        $("#somevalue").html(response.somevalue);
        loadSomething(response.somevalue);
    }, "jsonp");
    
    
    function loadSomething(somevalue) {
        $.get('/later.php', { n: somevalue }, function(response) {
            // Inject the response into the DOM or do something else
        });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本