首頁  >  文章  >  後端開發  >  javascript - 微信公众号,前台向后台发起ajax请求,后台获取不到发送过来的值是怎么回事??

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

WBOY
WBOY原創
2016-06-06 20:08:101387瀏覽

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>

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

考虑是否跨域了

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn