jQuery/ajax/php返回值

jQuery/ajax/php返回值,php,jquery,ajax,Php,Jquery,Ajax,我有一个注册表格,在提交时,验证密码和域名是否匹配。如果为true,我将尝试通过ajax请求检查DB中是否不存在域名 <div class="grid-6"> <p> <label for="First Name">First Name:</label> <input type="text" name="first_name" pl

我有一个注册表格,在提交时,验证密码和域名是否匹配。如果为true,我将尝试通过ajax请求检查DB中是否不存在域名

<div class="grid-6">
                <p>
                    <label for="First Name">First Name:</label>
                    <input type="text" name="first_name" placeholder="James" required value="">
                    <label for="Last Name" name="lastname">Last Name:</label>
                    <input type="text" name="last_name" placeholder="Brown" required value="">
                    <label for="email">Email:</label>
                    <input type="email" name="email" placeholder="email@email.com" required value="">
                    <label for="Preferred Password">Preferred Password:</label>
                    <input id="og_password" type="password" name="password" required value="">
                    <label for="Confirm Password">Confirm Password</label>
                    <input id="confirm_password" type="password" name="password_confirm" required value="">
                </p>
            </div><!-- /grid-6-->
            <div class="grid-6">
                <p>
                    <label for="Domain Name">Domain Name <span class="italic red">(lowercase letters and numbers only - no spaces):</span></label>
                    <input id="domain_name_a" type="text" name="domain_name_a" placeholder="mystudioname" required value="">
                    <label for="Domain Name">Confirm Domain Name:</label>
                    <input id="domain_name_b" type="text" name="domain_name_b" placeholder="mystudioname" required value="">
                </p>
            </div>
警报(域)返回正确的值,一切正常。问题在于domain.php文件中的某个地方、返回,或者仅仅是不正确地使用了.ajax。这里是php

PHP

<?php
    require_once("../includes/connection.php");

    $domainName = $_POST['domain'];

    $sql = "SELECT domain_name
            FROM user
            WHERE domain_name = '{$domainName}'
            ";
    $run = mysqli_query($mysqli, $sql);
    $result = mysqli_fetch_assoc($run);
    echo $result['domain_name'];
?>

如果我在这件事上出了什么差错,我们将不胜感激


谢谢

如果这是代码的直接副本-您在数据之后的ajax调用中缺少一个逗号:{},看起来您在
ajax请求中的数据和成功函数之间缺少一个逗号

data: {
    domain:domain
} , < -- Missing comma here
success: function(result) {
数据:{
域名:域名
},<--此处缺少逗号
成功:功能(结果){

出于某种奇怪的原因,jQuery无法通过缩短的url识别文件

解决方案是键入整个url->不仅是smtg/smtg.php,而且是


此外,您还可以尝试以json格式发送数据,方法是在ajax调用中添加以下代码行:“数据类型:'json',”,然后从php文件输出,如下所示:“echo json_encode(“返回值”);

谢谢!我尝试过了,但我的php返回值仍然存在问题。php代码验证并返回我需要单独运行的值。但我正在尝试警告成功的结果:没有可用的广告消息,我没有收到返回数据。返回数据是什么…看起来您没有以json格式从服务器发送数据检查什么$result是否在从服务器发送之前包含显示$result的最简单方法是什么。如果我独立于ajax请求运行domain.php文件,它将返回我请求的字符串。我更新了我的答案。您的代码中似乎有多个错误。作为提示,执行
$domainName=mysql\u real非常重要_escape_string($\u POST['domain']);
而不是
$domainName=$\u POST['domain']);
以避免出现错误。再次感谢。我没有得到任何返回数据。这使我认为问题出在我的PHP文件中。但是我独立运行该语句,它可以正常工作。在这种情况下,只需回显“test”;在PHP脚本的最开始,然后使用
$.get(“/actions/domain.PHP”,function(result){alert(result);});
如果您没有得到响应,那么系统就是找不到您告诉它要查找的文件,请尝试发送带有第一个斜杠的URL,如“actions/domain.PHP”,
data: {
    domain:domain
} , < -- Missing comma here
success: function(result) {