Sheldon Livingston
asked on
Simple ajax fix?
I'm trying to see if a user is attempting to use an Order ID that already exists.
My ajax code
The validateOrderNumber.php page:
I get a parseerror... unexpected token <
My ajax code
$.ajax({
type: "GET",
url:'validateOrderNumber.php',
data: "companyID=" + $("#companyID").val() + ",orderID='" + $("#orderID").val() + "'",
dataType: 'json',
success: function(data)
{
//Process results... should be either found or not found
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
The validateOrderNumber.php page:
<?php
include 'DBConnectionStuff.php';
$query = "select * from orders where customerID = " . $_GET["companyID"] . " and orderID = " . $_GET["orderID"];
$objConnection = new mysqli(Connection stuff);
$result=mysqli_query($objConnection,$query);
if (!$result) trigger_error('QUERY FAIL', E_USER_ERROR);
if(mysqli_num_rows($result) > 0){
echo json_encode("found");
}else{
echo json_encode("Not found");
}
mysqli_close($objConnection);
?>
I get a parseerror... unexpected token <
ASKER
I'm afraid that I really don't care about security, etc at this point.
I've spent a few hours just trying to get this to work. If and when it works then I'll try and worry about other stuff.
It amazes me as to how difficult this really is...
Anyway... this seems like a fairly simple task that shouldn't take more than 15 - 20 hours (of googling) to accomplish... yet it appears that it will.
I've spent a few hours just trying to get this to work. If and when it works then I'll try and worry about other stuff.
It amazes me as to how difficult this really is...
Anyway... this seems like a fairly simple task that shouldn't take more than 15 - 20 hours (of googling) to accomplish... yet it appears that it will.
Let's deconstruct the problem. What's the central issue here?
Is it getting the data from the client to the server? If so, a simple "bounce request" script like the one in the article can help.
Is it getting the query to work correctly? If so, you should be able to test the query from the browser address bar.
Or is it something else?
Is it getting the data from the client to the server? If so, a simple "bounce request" script like the one in the article can help.
Is it getting the query to work correctly? If so, you should be able to test the query from the browser address bar.
Or is it something else?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, I forgot to mention, you should change the PHP page output from -
echo json_encode("found");
Which makes no sense to me, an NOT USE the json_encode( ) , maybe like-
echo $_GET["orderID"]." : Found a Row";
else
echo "Not found for : ".$_GET["orderID"];
echo json_encode("found");
Which makes no sense to me, an NOT USE the json_encode( ) , maybe like-
echo $_GET["orderID"]." : Found a Row";
else
echo "Not found for : ".$_GET["orderID"];
ASKER
Thanks for the help folks
Have a look at this article for an example of how to send AJAX requests to a server-side script.
https://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
If you can post the rest of the client-side app (all HTML and JavaScript) I'll try to show you how to adapt it to work correctly.