473,411 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Jquery and Ajax Post issue

I have a home page from where I call another page insertfrm.php through Ajax. The problem is that insertfrm.php works fine when loaded directly in browser but does not work when loaded through ajax in div on home page.

home.php
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.  
  6.  
  7. <script type="text/javascript">
  8.  
  9. /***********************************************
  10. * Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
  11. * This notice MUST stay intact for legal use
  12. * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
  13. ***********************************************/
  14.  
  15. var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
  16. var loadedobjects=""
  17. var rootdomain="http://"+window.location.hostname
  18. var bustcacheparameter=""
  19.  
  20. function ajaxpage(url, containerid){
  21. var page_request = false
  22. if (window.XMLHttpRequest) // if Mozilla, Safari etc
  23. page_request = new XMLHttpRequest()
  24. else if (window.ActiveXObject){ // if IE
  25. try {
  26. page_request = new ActiveXObject("Msxml2.XMLHTTP")
  27. catch (e){
  28. try{
  29. page_request = new ActiveXObject("Microsoft.XMLHTTP")
  30. }
  31. catch (e){}
  32. }
  33. }
  34. else
  35. return false
  36. page_request.onreadystatechange=function(){
  37. loadpage(page_request, containerid)
  38. }
  39. if (bustcachevar) //if bust caching of external page
  40. bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
  41. page_request.open('GET', url+bustcacheparameter, true)
  42. page_request.send(null)
  43. }
  44.  
  45. function loadpage(page_request, containerid){
  46. if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
  47. document.getElementById(containerid).innerHTML=page_request.responseText
  48. }
  49.  
  50. function loadobjs(){
  51. if (!document.getElementById)
  52. return
  53. for (i=0; i<arguments.length; i++){
  54. var file=arguments[i]
  55. var fileref=""
  56. if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
  57. if (file.indexOf(".js")!=-1){ //If object is a js file
  58. fileref=document.createElement('script')
  59. fileref.setAttribute("type","text/javascript");
  60. fileref.setAttribute("src", file);
  61. }
  62. else if (file.indexOf(".css")!=-1){ //If object is a css file
  63. fileref=document.createElement("link")
  64. fileref.setAttribute("rel", "stylesheet");
  65. fileref.setAttribute("type", "text/css");
  66. fileref.setAttribute("href", file);
  67. }
  68. }
  69. if (fileref!=""){
  70. document.getElementsByTagName("head").item(0).appendChild(fileref)
  71. loadedobjects+=file+" " //Remember this object as being already added to page
  72. }
  73. }
  74. }
  75. </script>
  76.  
  77. <title>PHP Project</title>
  78. <link rel="stylesheet" type="text/css" href="layout.css" />
  79. </head>
  80. <body>
  81. <div id="pgwidth">
  82.         <div id="heading" >
  83.         <?php include("Menu/header.php"); ?>
  84.     </div>
  85.     <div id="wrapper">
  86.         <div id="navbar" Align="right" style="margin-right: 3px">
  87.             <?php include("Menu/navbar.php"); ?>
  88.         <!--end navbar--></div>
  89.         <div id="leftmenu">
  90.             <a href="javascript:ajaxpage('insertfrm.php', 'maincol');">New Head</a><br>
  91.         <!--end leftmenu--></div>
  92.         <div id="maincol">
  93.             <h1>PHP Test Project</h1>
  94.             <p>This is a test project to develop my HTML, PHP and mySQL skills</p>
  95.         <!--end maincol--></div>
  96.     <!--end wrapper--></div>
  97.     <div id="footer" Align="Center"><?php include("Menu/footer.php"); ?></div>
  98. <!--end pgwidth--></div>
  99. </body>
  100. </html>
  101.  
insertfrm.php
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/
  2. libs/jquery/1.3.0/jquery.min.js">
  3. </script>
  4. <script type="text/javascript" >
  5. $(function() {
  6. $(".submit").click(function() {
  7. var hcode = $("#HCode").val();
  8. var hname = $("#HName").val();
  9. //var username = $("#username").val();
  10. //var password = $("#password").val();
  11. //var gender = $("#gender").val();
  12. var dataString = 'HCode='+ hcode + '&HName=' + hname;
  13.  
  14. if(hcode=='' || hname=='')
  15. {
  16. $('.success').fadeOut(200).hide();
  17. $('.error').fadeOut(200).show();
  18. }
  19. else
  20. {
  21. $.ajax({
  22. type: "POST",
  23. url: "test2.php",
  24. data: dataString,
  25. success: function(){
  26. $('.success').fadeIn(200).show();
  27. $('.error').fadeOut(200).hide();
  28. }
  29. });
  30. }
  31. return false;
  32. });
  33. });
  34. </script>
  35.  
  36. <html>
  37. <body>
  38. <h3>Creating New Head</h3>
  39. <form method="post" name="form">
  40. <table>
  41. <tr>
  42. <td>Head Code:</td><td><input type="text" name="HCode" /></td></tr>
  43. <td>Head Type:</td><td><input type="text" name="HName" /></td></tr>
  44. <td></td><td><!input type="submit" /><!button type='submit' name='update' ><!/button>
  45. <input type="submit" value="Submit" class="submit"/>
  46. <span class="error" style="display:none"> Please Enter Valid Data</span>
  47. <span class="success" style="display:none"> Registration Successfully</span></td></tr>
  48. </table>
  49. </form>
  50. </body>
  51. </html>
  52.  
test2.php
Expand|Select|Wrap|Line Numbers
  1. <?php include("connectdb.php");
  2. if($_POST)
  3. {
  4. $sql="INSERT INTO headTB (HCode, HName)
  5. VALUES
  6. ('$_POST[HCode]','$_POST[HName]')";
  7.  
  8. if (!mysql_query($sql,$con))
  9.   {
  10.   die('Error: ' . mysql_error());
  11.   }
  12. //mysql_query("SQL insert statement.......");
  13. }else { }
  14.  
  15. mysql_close($con)
  16. ?>
  17.  
I don't know if I have explained my question well. Any help will be highly appreciated.
Nov 28 '10 #1
1 1758
Dormilich
8,658 Expert Mod 8TB
you are aware that you are not allowed to insert a complete HTML page into another HTML page?
Nov 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I...
1
by: nx.nine | last post by:
hi, i've done some searching and haven't found a solution that worked, hopefully someone here can help. i apologize in advance for my dyslexic thought process. i have an xml file being...
6
by: mosesdinakaran | last post by:
Hi Everybody, As all knows the difference between GET and POST is in the way how the data is transfered, But in case of ajax Though it may be a post Request we need to format a querystring...
1
by: pritisolank | last post by:
Hello Everyone, With that alert statment alert("calling validateme for "+document.form1.elements); in js things would work fine but if i remoe the form is simply getting submitted in firebug i can...
3
by: radix | last post by:
Hello, I have a aspx page with ajax scriptmanger update panel etc. I also have public string variables on the aspx page. Whenever postback happens from Ajax update panel, at server side all...
1
by: jrcapp | last post by:
Let's see if I can clearly explain what I am doing with AJAX. On my Web site, I have a TabContainer that has 2 TabPanels. Inside each Panel, I am dynamically (using a SQL query) creating an...
11
by: paitoon | last post by:
Hi, I have problem about ajax GET method. I use ajax to send mail and i use method GET. when i send alittle bit data it's work good but once i type so much in the form and send...i don't get...
3
sunbin
by: sunbin | last post by:
Hi, I am having in a Trouble when working with dynamic checkboxes (i.e. checkboxes with the same name, e.g. <input type="checkbox" name = "check" value="dynamic integer value">) I have...
1
blyxx86
by: blyxx86 | last post by:
Hey everyone, I'm fairly new to javascript. I hardly ever use it, but my newest project is demanding that I have 'dynamic' drop downs where the user can type in their partial matches. So, I...
2
by: amskape | last post by:
I created a script where a user can select from a variety of shipping options for an order from within a jQuery dialog box. The shipping rates are delivered via UPS & FedEx. Oddly enough, the ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
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...
0
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.