Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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中的Ajax未向PHP公式发送正确的键值_Php_Javascript_Jquery_Ajax_Key Value - Fatal编程技术网

jQuery中的Ajax未向PHP公式发送正确的键值

jQuery中的Ajax未向PHP公式发送正确的键值,php,javascript,jquery,ajax,key-value,Php,Javascript,Jquery,Ajax,Key Value,给出这两段代码: Javascript: /* Stores the received song. */ var receivedSong; /* Class: goearSong * * Description: Stores a song */ function goearSong(link, artist, title) { this.link = link; this.artist = artist; this.title = t

给出这两段代码:

Javascript:

/*  Stores the received song. */
var receivedSong;

/*  Class: goearSong            *
 *  Description: Stores a song  */
function goearSong(link, artist, title) {
    this.link = link;
    this.artist = artist;
    this.title = title;
}

function getGoearLink(code) {
    var key = 'id';
    var value = code;

    $.ajax({
        type: 'GET',
        url: 'goearScript.php',
        data: {key : code},
        success: function (response) {
            alert("Success!");
        },
        error: function (response) {
            alert("Error..." + response);
        },
        failure: function (response) {
            alert("Failure..." + response);
        }
    });

}

getGoearLink("06b3682");
PHP:

有人能解释一下这个问题吗?它快把我逼疯了

提前谢谢

编辑

PHP文件似乎不在根目录下,而是在/PHP/one下。因此,通过改变这一点,问题得以解决:

$.ajax({
        type: 'GET',
        url: 'goearScript.php',
为此:

$.ajax({
        type: 'GET',
        url: 'php/goearScript.php',

同时也改变了所选答案中提到的行。谢谢大家

您在
PHP
文件中使用
$\u GET['id']
,并且将
键作为
GET
参数传递,您需要传递
id
并添加
数据类型:'text',

将此
数据:{key:code},
替换为此
数据:{id:code},
,然后重试

更新的
函数getGoearLink
如下所示:

function getGoearLink(code) {
    $.ajax({
        type: 'GET',
        url: 'goearScript.php',
        dataType: 'text',
        data: {'id': code},
        success: function(response) {
            alert("Success!\n" + response);
        },
        error: function(response) {
            alert("Error..." + response);
        },
        failure: function(response) {
            alert("Failure..." + response);
        }
    });

}

它会出现什么错误?我刚刚做了,我担心它不起作用。。。现在看起来像数据:{id:code},但我仍然得到错误输出:SIt为我工作,您使用的是哪个版本的
jQuery
?您完全正确!我犯了一个愚蠢的错误。谢谢在
ajax
参数中添加
dataType:'text',
,更新答案,将
getGoearLink
替换为上述内容
$.ajax({
        type: 'GET',
        url: 'php/goearScript.php',
function getGoearLink(code) {
    $.ajax({
        type: 'GET',
        url: 'goearScript.php',
        dataType: 'text',
        data: {'id': code},
        success: function(response) {
            alert("Success!\n" + response);
        },
        error: function(response) {
            alert("Error..." + response);
        },
        failure: function(response) {
            alert("Failure..." + response);
        }
    });

}