Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从Jquery传递到php superglobals不起作用_Php_Jquery_Ajax_Request - Fatal编程技术网

将数据从Jquery传递到php superglobals不起作用

将数据从Jquery传递到php superglobals不起作用,php,jquery,ajax,request,Php,Jquery,Ajax,Request,我试图用Jquery将数据从js文件传递到php。但是,当我通过浏览器发送请求时,我会返回null值。我的php类$imageurl没有设置,我的超级全局$\u帖子也没有设置。我不知道为什么会发生这种情况,因为如果我通过postman设置fullimgurl,我的php请求就完全正常了。我试着把它解码并编码后寄回去。所有这些似乎都不起作用,这很奇怪,因为它通过邮递员起作用 以下是我的Jquery代码: <!DOCTYPE html> <html> <head>

我试图用Jquery将数据从js文件传递到php。但是,当我通过浏览器发送请求时,我会返回null值。我的php类$imageurl没有设置,我的超级全局$\u帖子也没有设置。我不知道为什么会发生这种情况,因为如果我通过postman设置fullimgurl,我的php请求就完全正常了。我试着把它解码并编码后寄回去。所有这些似乎都不起作用,这很奇怪,因为它通过邮递员起作用

以下是我的Jquery代码:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
</head>
<body>
<form enctype="multipart/form-data">
<input type="file" accept="image/*" onchange="loadFile(event)" >
<button name="submit" id="submit"></button>
</form>


<img src="" id="output"/>

<div id="textOutput"></div>

<script>
var imgfullurl;

$("#submit").on('click', function(e) {
    e.preventDefault();
    $.ajax({
        url: 'test1.php',
        type: 'POST',
        data: { imgfullurl: imgfullurl },
        dataType: "json",
        contentType : "application/json",
        success: function (data) {
            $('#textOutput').html(data);
            console.log(data);
        },
        error: function (error) {
            alert(error);
        }
    })
})


var loadFile = function(event) {
    var reader = new FileReader();
    reader.onload = function(){
        var output = document.getElementById('output');
        output.src = reader.result;
        imgfullurl = reader.result;
        console.log('imageurl');
        console.log(imgfullurl);
    };
    reader.readAsDataURL(event.target.files[0]);

};


</script>
</body>
</html>
尝试使用FormData

例如:

$( "#myForm" ).submit(function( event ) {
  event.preventDefault();

  url = $( "#myForm" ).attr( "action" );
  var formData = new FormData($(this)[0]);

  formData.append("yourkey", "yourvalue");

  $.ajax({
    url: url,
    type: 'POST',
    data: formData,
    async: false,
    cache: false,
    dataType: "json",
    contentType: false,
    processData: false,
    success: function (data) {
            if (data=='SUCCESS'){
            alert("Hi");
            //location.reload();

        }
            else

            alert("Something is Wrong !!"+data)
         }

  });

您是否尝试过
echo文件获取内容(“php://input");?在JavaScript中,其中定义了变量
imgfullurl
?您确定它已定义吗?在
$.ajax()
之前,您是否尝试过
console.log(imgfullurl)
?是的,这给了我一个加载处理程序violation@Syscall是的,我做了,它包含一个base64字符串,我会编辑它,为您提供js/jquery代码的其余部分。如果您执行类似
data:JSON.stringify({imgfullurl:imgfullurl)}的操作会怎么样
在将其传递给PHP之前?我仍然可以通过formdata键获取PHP中的值吗?是的,如果您看到可以将您的键附加到所需的值,即formdata.append(“imgfullurl”,imgfullurl);
$( "#myForm" ).submit(function( event ) {
  event.preventDefault();

  url = $( "#myForm" ).attr( "action" );
  var formData = new FormData($(this)[0]);

  formData.append("yourkey", "yourvalue");

  $.ajax({
    url: url,
    type: 'POST',
    data: formData,
    async: false,
    cache: false,
    dataType: "json",
    contentType: false,
    processData: false,
    success: function (data) {
            if (data=='SUCCESS'){
            alert("Hi");
            //location.reload();

        }
            else

            alert("Something is Wrong !!"+data)
         }

  });