如何在从javascript调用参数时将参数传递给php

如何在从javascript调用参数时将参数传递给php,javascript,php,json,Javascript,Php,Json,我正在从JavaScript调用一个PHP脚本。每当调用我的函数时,我都要设置tag=image。我该怎么做 函数httpGetAsync(URL,回调){ var xmlHttp=new XMLHttpRequest(); xmlHttp.onreadystatechange=函数(){ if(xmlHttp.readyState==4&&xmlHttp.status==200){ 回调(xmlHttp.responseText); } } open(“POST”,theUrl,true);

我正在从JavaScript调用一个PHP脚本。每当调用我的函数时,我都要设置
tag=image
。我该怎么做

函数httpGetAsync(URL,回调){ var xmlHttp=new XMLHttpRequest(); xmlHttp.onreadystatechange=函数(){ if(xmlHttp.readyState==4&&xmlHttp.status==200){ 回调(xmlHttp.responseText); } } open(“POST”,theUrl,true); xmlHttp.send(空); } httpGetAsync('storeImage.php'); 文件storeImage.php如下所示


存在冲突

  • xmlHttpRequest
    中,您正在触发一个
    GET
    请求。 但是,在
    storeImage.php
    中,您正在访问
    POST
    数据

  • httpGetAsync
    函数获得两个参数
    (url,回调)
    ,但调用函数时,只传递url

  • 正确的示例代码

    函数httpGetAsync(theUrl){ var xmlHttp=new XMLHttpRequest(); xmlHttp.onreadystatechange=函数(){ if(xmlHttp.readyState==4&&xmlHttp.status==200) 警报(xmlHttp.responseText); } open(“GET”,theUrl+“getData=hello”,true); xmlHttp.send(); }
    
    
    请参观一下

    好的,您有
    xmlHttp.open(“GET”
    然后
    $\u POST['tag']所以首先你需要决定你是想提出一个POST请求还是GET请求,然后在双方使用相同的术语。我已经更新了我的问题。现在我该怎么做呢?可能是的,你需要将其更改为
    POST
    我已经尝试了GET和POST。但是它不起作用。我已经上传了我的全部code、 你能告诉我哪里出了问题吗?