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

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

WBOY
WBOYOriginal
2016-06-06 20:08:101452browse

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>

后台:

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

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

回复内容:

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>

后台:

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

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

考虑是否跨域了

Statement:
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