-2

Trying to pass data to the server but it keeps returning a "Parameter Missing"

So either the data is not being passed to the PHP script or I am doing something wrong.

Here is the jQuery:

function quickJob(obj) {

    var quickJobNumber = $(obj).text();
    //alert(quickJobNumber)
    $.ajax({
        type: "GET",
        url: "quickJobCB.php",
        data: quickJobNumber,
        success: function(server_response)
        {
            $("#message").removeClass().html(server_response);
        }
    });
}

Ok....when tracing the issue I created an alert as seen below. The alert is producing the expected results.

Here is the PHP script:

<?php

require_once("models/config.php");


// Make the connection:
$dbc = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);

if (!$dbc) {
    trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}

if (isset($_GET['quickJobNumber'])) {
    $quickJobNumber = trim($_GET['quickJobNumber']);
    $quickJobNumber = mysqli_real_escape_string($dbc, $quickJobNumber);

    $query = "SELECT * FROM projects WHERE projectNumber = '" . $quickJobNumber . "'";
    $result = mysqli_query($dbc, $query);


    if ($result) {
        if (mysqli_affected_rows($dbc) != 0) {
            while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

                echo $row['projectName'];
            }
        } else {
            echo 'No Results for :"' . $_GET['quickJobNumber'] . '"';
        }
    }
} else {
    echo 'Parameter Missing';
}
?>

<?php include("models/clean_up.php"); ?>
2
  • 3
    Please make an effort to use descriptive titles instead of vague ones like "PHP jQuery AJAX", this will make your question much more useful to everyone else looking for an answer to something. Commented Aug 25, 2011 at 0:44
  • if you're using firefox, install the Live Http Headers add-on, to see which values you're passing to quickJobCB.php. Commented Aug 25, 2011 at 0:47

3 Answers 3

3

data: quickJobNumber,

should be

data: { 'quickJobNumber': quickJobNumber },

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that did it!!! I guess I was too close to the code....as a side note please change your script to: data: { 'quickJobNumber': quickJobNumber },
0

You'll need to pass the data either as a query string like so

data: "quickJobNumber="+quickJobNumber,

or a map like so

data: data { quickJobNumber: quickJobNumber },

Comments

0

If you want to use the GET request, use $.get

$.get("/get_request.php", { quickJobNumber: "myAjaxTestMessage"},
   function(data){
     console.log("WOW! Server was answer: " + data);
});

In php

<?php
if(isset($_GET['quickJobNumber'])){
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode(array('answer'=>'Hello user!'));
}
?>

If you want to use the POST request, use $.post

$.post("/post_request.php", { quickJobNumber: "myAjaxTestMessage"},
   function(data){
     console.log("WOW! Server was answer: " + data);
});

In php

<?php
if(isset($_POST['quickJobNumber'])){
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode(array('answer'=>'Hello user!'));
}
?>

P.S. or you can use $_REQUEST in php.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.