bob_the _builder Posted January 8, 2009 Share Posted January 8, 2009 Hey, Using the code from sticky "AJAX - a basic start and working example" how can you send post data into the div tags? I have it working ok for all links that are text base but cant manage to post form data and load in the div tag. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/140075-ajax-post-data/ Share on other sites More sharing options...
Philip Posted January 9, 2009 Share Posted January 9, 2009 I'm not sure what you're really wanting, when you say "send post data into the div tags" - do you want to show the variables you're sending or receiving show into a div area? Quote Link to comment https://forums.phpfreaks.com/topic/140075-ajax-post-data/#findComment-733005 Share on other sites More sharing options...
bob_the _builder Posted January 9, 2009 Author Share Posted January 9, 2009 Hey, I want to submit the form and have it process the php script within the div tag. As you would using the get method within a link like: <a href=\"javascript: AjaxRequest('main','".$_SERVER['PHP_SELF']."?action= Thanks Quote Link to comment https://forums.phpfreaks.com/topic/140075-ajax-post-data/#findComment-733029 Share on other sites More sharing options...
Philip Posted January 9, 2009 Share Posted January 9, 2009 Well, if you're wanting it to return PHP code and then execute it on the first page - it won't. Remember, PHP is server side, not client side like javascript. Maybe I'm still not understanding it? Quote Link to comment https://forums.phpfreaks.com/topic/140075-ajax-post-data/#findComment-733035 Share on other sites More sharing options...
bob_the _builder Posted January 9, 2009 Author Share Posted January 9, 2009 Hi, Ajax? function AjaxRequest(target_div,file,check_div) { var MyHttpRequest = false; var MyHttpLoading = '<table height="238" width="100%" border="0"><tr><td align="center" valign="middle"><img src="./loading.gif"></td></tr></table>'; var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, buy a newspaper instead'; if(check_div) { var check_value = document.getElementById(check_div).value; } else { var check_value = ''; } if(window.XMLHttpRequest) { try { MyHttpRequest = new XMLHttpRequest(); } catch(e) { MyHttpRequest = false; } } else if(window.ActiveXObject) { try { MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { MyHttpRequest = false; } } } else { MyHttpRequest = false; } if(MyHttpRequest) { var random = Math.random() * Date.parse(new Date()); var file_array = file.split('.'); if(file_array[1] == 'php') { var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') { var query_string = ''; } else { var query_string = check_value + '&rand=' + random; } MyHttpRequest.open("get", url_encode(file + query_string), true); MyHttpRequest.onreadystatechange = function () { if(MyHttpRequest.readyState == 4) { document.getElementById(target_div).innerHTML = MyHttpRequest.responseText; } else { document.getElementById(target_div).innerHTML = MyHttpLoading; } } MyHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); MyHttpRequest.send(null); } else { document.getElementById(target_div).innerHTML = ErrorMSG; } } As it stands I can submit links ($_GET) data and have it query the database and bring back the results within the div tags, but I cant make data sent within a form query the database and bring back results within the div tag.. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/140075-ajax-post-data/#findComment-733068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.