我试图与myqli进行一次ajax通话。
因为我正在测试用户的数据库输入。

该脚本在以下位置崩溃:$ testBase = new mysqli(“ sfd”,“ sdf”,“ sdg”,“ sdf”);

并在控制台中显示:Uncaught SyntaxError:意外的令牌<

是的,您搜索了这个问题,但大多数人在执行查询时会收到该错误,而当我尝试创建mysqli连接时,我已经在执行该操作了。

Ajax脚本:

if (error == false){
var name = $('#name').val(),
    url = $('#url').val(),
    datahost = $('#datahost').val(),
    datausername = $('#datausername').val(),
    datapassword = $('#datapassword').val(),
    dataname = $('#dataname').val(),
    license = $('#license').val(),
    data = 'name='+ name +'&url='+ url +'&datahost='+ datahost +'&datausername='+ datausername +'&datapassword='+ datapassword +'&dataname='+ dataname +'&license='+ license;

$( "#trans" ).fadeIn( 500, function() {
    $.ajax({
        type: "POST",
        url: "handlers/install.php",
        data: data,
        success: function(e){ // this happen after we get result
            react(e);
        }
    });
});


}

请帮我

handelers / install.php的响应为:

"<br />\n<b>Warning</b>:  mysqli::mysqli(): (HY000/1130): Host 'server2.ughost.nl' is not allowed to connect to this MySQL server in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>59</b><br />\n<br />\n<b>Warning</b>:  mysqli::close(): Couldn't fetch mysqli in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>75</b><br />\n{\"ban\":0,\"error\":0,\"license\":0,\"url\":0,\"name\":0,\"sql\":0,\"message\":\"localhost + asd + asdas+dasf\"}"

最佳答案

好的,问题是,当登录不正确时,install.php总是发出警告。
但是我需要检查它,因为这是用户的输入,所以我如何解决呢?

error_reporting(0);
                        $testBase = new mysqli($datahost, $datausername, $datapassword, $dataname);
                        error_reporting(1);
                        if ($testBase->connect_errno) {
                            $response['sql'] = 1;
                            $testBase->close();
                        } else {
                            //can connect with database
                            $testBase->close();

                        }

关于php - ajax无法与mysqli连接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29335244/

10-11 13:22