Posted on February 1st, 2007
18914 views
The only thing you need to have and I'm not explaining is a function to get the AJAX xml.
If you don't have it heres the one I use: [code] function getXhttp ( ) { var ajax_request; if ( window.ActiveXObject ) { var mSoftVersions = [ 'MSXML2.DOMDocument.5.0', 'MSXML2.DOMDocument.4.0', 'MSXML2.DOMDocument.3.0', 'MSXML2.DOMDocument.2.0', 'MSXML2.DOMDocument', 'Microsoft.XmlDom', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ]; for ( i=0; i<mSoftVersions.length; i++ ) { try { ajax_request = new ActiveXObject ( mSoftVersions[i] ); } catch ( e ) { } } } else if ( !ajax_request && typeof XMLHttpRequest != 'undefined' ) { try { ajax_request = new XMLHttpRequest; } catch ( e ) { } } else if ( !ajax_request && window.createRequest ) { try { ajax_request = window.createRequest; } catch ( e ) { } } else { ajax_request = false; } return ajax_request; }[/code] Okay, now that, that's out of the way, sending a request with AJAX using POST is a lot easier than it seems. First you declare a function like.. add news or something:
You set up your AJAX Request var and test to see if its available.
So what we've done so far is set the variable xml to the function. Then tested the variable wheter its false, if it is, it will return false and end the add_news(); function. The next part is to change the content-type of the page to submit the form.
The only thing left to do is send the form data, so what you want to do is put your fields in variables and send them.
Now in post_news.php you need to:
so post_news.php: <?php Basic shit. <3 |