Jquery load() and PHP variables

前端 未结 6 841
死守一世寂寞
死守一世寂寞 2020-12-03 00:29

If I load a PHP page with Jquery .load(file.php), can the included file use the php variables that were defined on the page that called the load()?

6条回答
  •  伪装坚强ぢ
    2020-12-03 00:37

    The second argument (params) of the JQuery load function should be an object or a callback function, but could also be an empty string. Depending on that, load does send post or get requests.

    I had the idea to switch automatically between get and post, (for example if cookie set),because get is more fast and cache able, and post is more save.

    Its worse to write the load function including the content inside the callback function twice than to write something like that:

    //get
    var url="cache_dir/my_bag.html";
    var params="";
    if(document.cookie){
      //post
      url="post.php";
      params="{my:bag}";
      }
    $(selector).load(url,params,function(){
    ...
    
      });
    

提交回复
热议问题