代码未在$ .get()成功处理程序中运行 - php

这是我的两个jQuery函数

$(".enable_button").click(function(){
    var server_name = $(this).attr("title");
    $.get("ajax/server_ajax.php?action=enable&server_name=" + server_name), function(data) {
        alert(data);
    }
});

$(".disable_button").click(function(){
    var server_name = $(this).attr("title");
    $.get("ajax/server_ajax.php?action=disable&server_name=" + server_name), function(data) {
        alert(data);
    }
});

只需按一下按钮,即可通过将action参数和server_name参数传递给ajax/server_ajax.php来启用或禁用服务器,这很容易看出它们的作用。一切正常,但是由于某种原因,返回的数据永远不会被警告。我可以验证它正确地请求了PHP文件,并且PHP文件正在返回数据,正如我在Firebug的“ Response”标签中所看到的那样。

我也尝试过用document.write(data)替换警报,但也不起作用。

谁能伸出援手?我一无所知。

参考方案

您太早关闭对get()的呼叫。 + server_name之后的括号不应存在。

$.get("ajax/server_ajax.php?action=disable&server_name=" + server_name), function(data) {
                                                                    //^The ) shouldn't be here
    alert(data);
}

应该

$.get("ajax/server_ajax.php?action=disable&server_name=" + server_name, function(data) {
    alert(data);
}); //<-- close the call to get( over here, not after server_name.

暂且不说,但是有了jQuery的ajax函数,您就可以传递数据对象,而jQuery会从中创建查询字符串,将所有需要的字符串整齐地转义。因此,您可以执行此操作,这等效于您最初对disable的调用:

$.get("ajax/server_ajax.php", {"action" : "disable", "server_name" : server_name}, function(data) {
    alert(data);
});

下载file_get_contents响应 - php

我有以下jQuery:$(".download").click(function(){ $.post('get_bot.php', "url_code="+url_code, function (response) { alert(response); }); }); url_code是一个具有js…

AJAX和file_get_contents - php

我有一个使用file_get_contents的脚本,然后解码返回的JSON ...$urlone = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=f…

PHP:file_get_contents($ loc)失败 - php

我只是将一个项目从localhost移到了我的远程服务器上,并且注意到我的某些脚本停止工作了。最重要的是依赖file_get_contents()从另一个脚本中获取JSON值的脚本。PHP版本是5.2.4allow_url_fopen开启 警告:file_get_contents() [function.file-get-contents]:php_netw…

jQuery Ajax PHP重定向到另一个页面 - php

JavaScript文件:$.ajax({ type: "POST", url: "ajax.php", data: dataString, success: function(r) { $("#div").html(r); } }); 我想在成功的情况下将页面重定向到new.php,所以在我使用a…

jQuery ajax()返回json对象,但未正确警告 - php

为什么无法使用data [0] .id返回ID? $(document).ready(function(){ $.ajax({ type: 'POST', dataType: "json", url: '<?php echo matry::base_to('tests/map_it'…