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

查看:356
本文介绍了javascript - 微信公众号,前台向后台发起ajax请求,后台获取不到发送过来的值是怎么回事??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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

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);
  }
  

后台:

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

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

解决方案

考虑是否跨域了

这篇关于javascript - 微信公众号,前台向后台发起ajax请求,后台获取不到发送过来的值是怎么回事??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆