Ajax通话不起作用

时间:2014-07-24 13:48:50

标签: php jquery ajax

好吧,伙计们,这让我疯了,我有这个工作,但似乎我没有抓住我的ajax调用我的PHP文件中的任何变量..我回应出来,只看到没有价值...谁能解释什么我在这里做错了,我找不到任何错误,

 var owner_name = $('#owner_name').html();
 var owner_email = $('#owner_email').html(); 
 var owner_mobile = $('#owner_mobile').html(); 
 var owner_phone = $('#owner_phone').html(); 

function jobcardCreate() {

$.ajax({
    dataType: 'json',
    url: './ajax/jobcard-send.php',
    type: 'POST',
    data: {
        owner_name: owner_name, 
        owner_email: owner_email, 
        owner_mobile: owner_mobile, 
        owner_phone: owner_phone,
        },       
    success: function(data) {

    }
});

 }

jobcard-send.php:

<?php

    include("../includes/connection.php");

    $owner_name = $_POST['owner_name'];
    $owner_email = $_POST['owner_email'];
    $owner_mobile = $_POST['owner_mobile'];
    $owner_phone = $_POST['owner_phone'];

    // Insert new data into users table
    $query  = " INSERT INTO"; 
    $query .= " owner";
    $query .= " (owner_name, owner_email, owner_mobile, owner_phone)";
    $query .= " VALUES";
    $query .= " ('{$owner_name}', '{$owner_email}', '{$owner_mobile}', '{$owner_phone}')";

    echo $owner_name;
    echo $query; 

    $result = mysqli_query($connection, $query);

    //Check if there was an error with the query
     if ($result) {
        echo json_encode(array("status" => "$owner_name"));
    } else {
        echo "Database query failed, " . mysqli_error($connection) . "";
    }   

?>
在我工作之后,已经浪费了很多个小时,:/

这是html:

    <div class="card-content one-third">
        <div class="list-title thin">Owner Contact</div>
        <ul class="detail-list">
            <li class="button rounded"><a class="list-heading">Name:</a> <a id="owner_name" class="list-result-edit" contenteditable="true"></a></li>
            <li class="button rounded"><a class="list-heading">Email:</a> <a id="owner_email" class="list-result-edit" contenteditable="true"></a></li>
            <li class="button rounded"><a class="list-heading">Mobile No:</a> <a id="owner_mobile" class="list-result-edit" contenteditable="true"></a></li>
            <li class="button rounded"><a class="list-heading">Phone No:</a> <a id="owner_phone" class="list-result-edit" contenteditable="true"></a></li>
        </ul>
    </div>

1 个答案:

答案 0 :(得分:2)

var owner_name = $('#owner_name').html();和朋友将在脚本运行时获取你的锚的innerHTML,这是页面加载时(因此在用户输入任何内容之前)。< / p>

移动您尝试阅读innerHTML,以便内部 jobcardCreate函数。