简体   繁体   English

Post参数不会从ajax请求发送到PHP

[英]Post Parameters are not sent to PHP from ajax request

My Request 我的请求

jQuery.ajax({               
                url: 'PHPdocs/appsearch.php',
                data: {term:'blub'},
                type: "POST",
                async: true,
                data: "text",
                success: function(msg){
                    $('div[data-role="content"]').append(msg);
                    },
                error: function(msg){}})    

my PHP File 我的PHP文件

$json = file_get_contents("https://itunes.apple.com/search?country=de&entity=software& 
term=".$_POST['term'];);
$results = json_decode($json, true);
echo $json;

What i Get as result 我得到的结果

Notice: Undefined index: term in C:\xampp1\htdocs\AppRain\PHPdocs\appsearch.php on line 3
{ "resultCount":0, "results": [] } 

I need to sent the term to search from my jscode to the php file via Post but everything i tried did not work. 我需要通过Post发送该术语以从我的jscode搜索到php文件,但是我尝试的所有方法均无效。

I also triedto set type to GET so that it ist a Get request but the Ajax did not work. 我还尝试将type设置为GET,以便它发出Get请求,但Ajax无法正常工作。 But when i used get i could use it with the URL apprain.php?term=.... without i only copied it to the url field from the browser. 但是当我使用get时,可以将其与URL apprain.php?term = ....一起使用,而无需将其仅从浏览器复制到url字段。 It seems that every parameter sent over $.ajax or jQuery.ajax is blocked Please can someone help me. 似乎通过$ .ajax或jQuery.ajax发送的每个参数都被阻止,请有人帮帮我。

You are overwriting you data key: 您正在覆盖data密钥:

data: "text",

You should remove that line. 您应该删除该行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM