I have a form that populates data from database upon clicking on a fetch button and fills the other fields.
It works fine fine with the exception that it should display an error message if it retrieves nothing. Can someone help me write the failure function.i.e if the form returns nothing when u click on the fetch button,it should display some kind of error message.
Here is my code for form: - <input type="text" name="username" id="username">
-
<div id="formResponse"></div>
-
<button id="fetchFields">fetch</button>
-
<label for="posts">Posts: </label>
-
<input type="text" size="20" name="posts" id="posts">
-
<label for="joindate">Joindate: </label>
-
<input type="text" size="20" name="joindate" id="joindate">
-
-
-
-
<p><input type="submit" value="Submit" name="submitBtn"></p>
-
-
</fieldset>
-
</form>
-
-
<script type="text/javascript">
-
$(document).ready(function() {
-
function myrequest(e) {
-
var name = $('#username').val();
-
$.ajax({
-
method: "GET",
-
url: "autofill.php",
-
dataType: 'json',
-
cache: false,
-
data: {
-
username: name
-
},
-
success: function( responseObject ) {
-
alert('success');
-
$('#posts').val( responseObject.posts );
-
$('#joindate').val(responseObject.joindate);
-
/*
-
once you've gotten your ajax to work, then go through and replace these dummy vals with responseObject.whatever
-
*/
-
},
-
failure: function()
-
{
-
alert('fail');
-
}
-
});
-
}
-
-
$('#fetchFields').click(function(e) {
-
e.preventDefault();
-
myrequest();
-
});
-
});
here is my autofill.php -
<?
-
$name = stripslashes($_GET['username']);
-
-
-
$return = mysql_query("SELECT posts,joindate FROM user WHERE username = '$name' LIMIT 1");
-
if(mysql_num_rows($return) > 0)
-
{
-
$rows = mysql_fetch_assoc($return);
-
$formattedData = json_encode($rows);
-
echo $formattedData;
-
}
-
-
?>
-
[/quote]
1 1615 Dormilich 8,658
Recognized Expert Moderator Expert
rename failure to error.
but that won’t help you since no content is not a failure (it is, so-to-speak, only an empty string). to properly deal with that issue you could use HTTP headers. there is for instance "HTTP\1.1 204 No Content" which you can intercept with the statusCode property.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: David Logan |
last post by:
We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.
|
by: Shaggers |
last post by:
I need to hide/not display a blank row on a subform.
The Main form is based on a table, contains Site Header information
The Subform is based on another table containing Sample Details records
Site Header table to Sample Details table relation ship is one-to-many,
with two key fields SiteID and SiteVisitDate
The Form/SubForm is linked by SiteID, SiteVisitDate
The form adds one record to the Site Header Table.
|
by: Viktor |
last post by:
I have a problem with counting empty fields in table.
For example: I have the field in which i coulld write several solutions.
"done", "not done", "send", "not send" etc.
In report i want to count how many records in that filed is empty and the records which have written any solution in that filed.
I would be grateful for any solution.
|
by: naboumerhi |
last post by:
Hi,
I have a a custom report trying to hide empty fields and shift the next field up.
It still shows and empty space.
Example:
company1
company2
company3
|
by: elsheh |
last post by:
Hi.. guys
I’m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.
Any clue?
<html>
<head>
<script language="JavaScript">
function isEmpty(inputStr,fieldname){
if (inputStr==null || inputStr==""){
| |
by: Eric Layman |
last post by:
Hi everyone,
I noticed that customevalidator won't work with empty fields. But I do not
want to put in another requiredfieldvalidator
Any workarounds?
I've tried
if args.Text.trim.length() = 0 then
|
by: Phaelle |
last post by:
In my database, some fields are empty for some recordings.
And I wouldl like that the empty fields don´t appear on the answer page of my search engine or, in other worlds, that I don´t have that kind of things (ie age without anything):
Surname : Sawers
First name : Tom
Age:
Nationality : American
Thanks a million!
|
by: JFKJr |
last post by:
Hello everyone, I have imported an excel file into an Access table, but the table contains some empty fields, does anyone know how to delete those empty fields using Access VBA?
Thanks in Advance.
|
by: code green |
last post by:
How can empty fields be detected.
SELECT * FROM products WHERE
description IS EMPTYThe field may be NULL
or just empty and I suppose even space characters.
|
by: FKlusmann |
last post by:
I have inherited a big, messy table with duplicated data and empty fields consisting of Names (business, client, supplier, etc.), Addresses ( physical, mailing, shipping, billing), Orders ( Date, item, quantity, price, shippedby, shipdate, shipcost), etc..
I wish to "normalize" this without loosing data.
MainTable.ID -> NamesTable (NameID, NameType, LName, FName, etc....)
-> AddressTable (AddressID, Type, Line1, Line2,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |