javascript - 微信公众号,前台向后台发起ajax请求,后台获取不到发送过来的值是怎么回事??

WBOY
Release: 2016-06-06 20:08:10
Original
1423 people have browsed it

Ecshop后台:
微信公众号前台:

<code>try{
    function getData(method,path,searchStr,dataType,fn){
      var xhr=new XMLHttpRequest();
      method=method.toUpperCase();
          xhr.open(method.toLowerCase(),(method==='POST') ? path : path+'?'+searchStr,true);
          if (method==='POST'){
            xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
          }
          xhr.send((method==='POST') ? searchStr : null);
          xhr.onreadystatechange=function(){
            if (this.readyState===4 && this.status===200){
              var data=this.responseText;
             
              alert('fanyingshuju: '+data);
            }
          }
    }
    getData('GET','goods.php','act=price&id=' + goodsId + '&attr=' + attr + '&number=' + qty, changePriceResponse);
    
  }catch(err){
    alert('error: '+err);
  }
  </code>
Copy after login
Copy after login

后台:

<code> die('发起的请求: '.$_REQUEST['act']);
</code>
Copy after login
Copy after login

这个地方总是获取不到值,究竟是怎么回事??

回复内容:

Ecshop后台:
微信公众号前台:

<code>try{
    function getData(method,path,searchStr,dataType,fn){
      var xhr=new XMLHttpRequest();
      method=method.toUpperCase();
          xhr.open(method.toLowerCase(),(method==='POST') ? path : path+'?'+searchStr,true);
          if (method==='POST'){
            xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
          }
          xhr.send((method==='POST') ? searchStr : null);
          xhr.onreadystatechange=function(){
            if (this.readyState===4 && this.status===200){
              var data=this.responseText;
             
              alert('fanyingshuju: '+data);
            }
          }
    }
    getData('GET','goods.php','act=price&id=' + goodsId + '&attr=' + attr + '&number=' + qty, changePriceResponse);
    
  }catch(err){
    alert('error: '+err);
  }
  </code>
Copy after login
Copy after login

后台:

<code> die('发起的请求: '.$_REQUEST['act']);
</code>
Copy after login
Copy after login

这个地方总是获取不到值,究竟是怎么回事??

考虑是否跨域了

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template