i went to tizags ajax mysql tutorial(how to update mysql with ajax)
i dont understand it seems like that example is wayyyyy too long i cant comprehend it it makes no sense. does anyone know of a good way to explain to me how to update / insert a value into one field in my case its tags in the mysql table.
like i want to be able to tag a post with multiple words seperated by a comma whatever i just want to know how to do it with ajax without reloading the page anyone know the code or something it seems rather easy but i cant understand how to do it or where to find out to do it so im asking here.
?
SKANK!!!!! 5 Posting Pro in Training
essential 84 Posting Shark Featured Poster
Hi,
Here is a simple demo:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Window-target" content="_top">
<title>Free Live Help!</title>
<script type="text/javascript">
<!--
// OBJECT BUILDER \\
var AjaxObjectBuilder = ( function() {
/* The variable : ( isXMLHttp )
- Will served as our verifyer
to check whether or not
the browser understand
the XMLHttpRequest instance. */
var isXMLHttp = !!( window.XMLHttpRequest );
/* The variable : ( xmlHttp )
- Will be used to hold the
object request instance
build by either two of the
following request's object:
1. new XMLHttpRequest() - will create an object request for non-IE based browser.
2. new ActiveXObject( prodId ) - for an IE based browser. */
var xmlHttp = null;
if ( isXMLHttp ) // for the browser that understand XMLHttpRequest object
xmlHttp = new XMLHttpRequest(); // request object created.
else if ( "ActiveX" in window ) { // Statement for IE
try { // try if it does understand the first prodId.
xmlHttp = new ActiveXObject( "MSXML2.XMLHTTP" ); // Compatible with IE6+
} catch( e ) { // this goes to IE5
xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
}
} else { xmlHttp = 0; } // if both conditions failed, this will return 0;
return xmlHttp;
} );
// this functions can be modularized, so that it can be called using one syntax's for the function.
/* But in this demo i have created a different sets of functions for each process -
so that you can easily understand how they work */
var xmlDoc = AjaxObjectBuilder(); // Holds our created request object.
/* The next procedure is to process this created XMLHttp object ( xmlDoc ) */
// REQUEST HANDLER \\
var handleRequest = ( function() { // Where all the action takes place.
alert( "Current request status : ( " + ["uinitialized", "loading", "loaded", "interactive", "complete"][ xmlDoc.readyState ] + " )" );
if ( xmlDoc.readyState === 4 || xmlDoc.readyState === "complete" ) { // Request is completed.
if ( xmlDoc.status === 200 ) { // Server response is ok
alert( xmlDoc.responseText );
return;
}
} alert( "Request failed: " + xmlDoc.statusText );
} );
// REQUES BUILDER \\
/* This function requires atleast 1 parameter ( str ) into it.
This parameter will then be used to hold our values from the user interaction or with any events action. */
var AjaxRequestBuilder = ( function( str ) {
var url = "processDb.php"; // Any valid path to your document that processes your database.
var str = str || ""; // Any qualified query string
var qstr = "?qdb=" + str + "&qid=" + Math.random(); // Lets add a random number to restrict the server from using a cached file.
// Lets make sure that we dont get zero value from the request object.
if ( xmlDoc ) { // successfull execution of the object. Things to do -->
(( "overrideMimeType" in xmlDoc ) ? xmlDoc.overrideMimeType("text/xml") : xmlDoc ); // Gecko based standard, for its application MimeType that will be passed onto the request object.
// processing the OnReadyStateChanged:
xmlDoc.onreadystatechange = handleRequest; // your callback function.
xmlDoc.open( "POST", url, 1 );
/* gaining access from the file path ( processDb.php ).
NOTE : that the type of request should be at "POST" when you are making changes/updates over server-side process.
In this case we are updating fields in db, so i have used "POST" over its request type, instead of normal "GET". */
(( "setRequestHeader" in xmlDoc ) ? xmlDoc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8;") : xmlDoc ); // Setting the content mime type is required when you are "POST"ing request.
xmlDoc.send( qstr ); //Sends out our queryString to the database.
}
} );
onload = function() {
AjaxRequestBuilder( "yourQString" );
}
// -->
</script>
</head>
<body>
<div id="main"></div>
</body>
</html>
Please read the instructions inside the script...
essential
SKANK!!!!! 5 Posting Pro in Training
thx bbut i dont get what it does
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.