duandeng7132 2014-08-09 14:20
浏览 31
已采纳

如何通过单击标记来更改PHP变量

I just want use ajax to change some variables in PHP code, I search so long time and dont get answers.

there is a a variable which called $args, it's an array,

$arg=array(
    'paged' => $paged,
    'author'=> $author_ID,
    'showposts'=>  $author_posts_num,
    'post_status'=>'publish'
)

and I want to click on a tag, change some variables or add some to $arg,I know PHP is compiles on the server, but what I though is can I change the the variable above before the server compile php code, I mean is this possible: 1:click the tag(maybe a button) 2: change variable above 3: the server compile PHP 4: hte HTML page reload 5: and we see the HTML page has changed

I just new to PHP AJAX, so a little confused here, thank you so much

  • 写回答

3条回答 默认 最新

  • dongzai5181 2014-08-09 14:24
    关注

    I just want use ajax … can I change the the variable above before the server compile php code

    No. If you are using Ajax, then this is what happens:

    1. Browser requests URL
    2. Server runs PHP and sends the output to the browser
    3. Browser runs JavaScript
    4. JavaScript tells browser to request another URL
    5. Server runs PHP and sends the output to the browser
    6. JavaScript can do something with the result

    hte HTML page reload

    If you want to reload the page: Don't use Ajax. The entire point of Ajax is to get new content from the server without reloading the page.

    Just submit a form to the server and have PHP run and deliver a new page based on the user inform from the form submission.

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

报告相同问题?