没有使用Ajax请求发布参数

时间:2012-04-14 13:20:46

标签: php ajax

此Ajax请求有效,但似乎参数未发布到getHint.php($_POST['targetId']为空)。我有什么想法吗?

非常感谢

postAjaxRequestFunktion(minFunktion, 'getHint.php', 'targetId = ' + playId)

         function postAjaxRequestFunktion(minFunk,minUrl, mittArg)
         {
            var contenttype = 'application/x-www-form-urlencoded'
            var minRequest        = new skapaAjaxObjekt(minFunk)
            if (!minRequest) return false
            minRequest.open('POST', minUrl, true)
            minRequest.setRequestHeader('Content-type',   contenttype)
            minRequest.setRequestHeader('Content-length', mittArg.length)
            minRequest.setRequestHeader('Connection',     'close')
            minRequest.send(mittArg)
            return true
         }


         function skapaAjaxObjekt(minFunk)
         {
            try       { var   minRequest = new XMLHttpRequest()                   }
            catch(e1) { try { minRequest = new ActiveXObject("Msxml2.XMLHTTP")    }
            catch(e2) { try { minRequest = new ActiveXObject("Microsoft.XMLHTTP") }
            catch(e3) { minRequest = false }}}
            if (minRequest) minRequest.onreadystatechange = function()
            {
               if (this.readyState == 4 && this.status == 200 &&
                   this.responseText != null)
                     minFunk.call(this.responseText)
            }

            return minRequest
         }  

         function minFunktion()
         {
             hintArray = eval('(' + this + ')');    
         }

getHint.php:

$targetId = $_POST['targetId'];

1 个答案:

答案 0 :(得分:1)

我建议你使用js lib jQuery,其中ajax请求更简单.. 也在php文件使用 后续代码var_dump($ _ POST); 会给你更多信息