Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][AJAX] Problem z formularzem
kropla
post
Post #1





Grupa: Zarejestrowani
Postów: 62
Pomógł: 0
Dołączył: 16.12.2005

Ostrzeżenie: (10%)
X----


Witajcie

Próbuję zrobić formularz który będzie przesyłał dane wykorzystując ajax-a. Trochę poczytałem i znalazłem stronę:

http://www.captain.at/howto-ajax-form-post-get.php

problem mam taki że jak skopiuję sobie kod do swojego pliku to dostaję komunikat There was a problem with the request.

poniżej zawartosc pliku
  1. <script type="text/javascript" language="javascript">
  2. var http_request = false;
  3. function makeRequest(url, parameters) {
  4. http_request = false;
  5. if (window.XMLHttpRequest) { // Mozilla, Safari,...
  6. http_request = new XMLHttpRequest();
  7. if (http_request.overrideMimeType) {
  8. // set type accordingly to anticipated content type
  9. //http_request.overrideMimeType('text/xml');
  10. http_request.overrideMimeType('text/html');
  11. }
  12. } else if (window.ActiveXObject) { // IE
  13. try {
  14. http_request = new ActiveXObject("Msxml2.XMLHTTP");
  15. } catch (e) {
  16. try {
  17. http_request = new ActiveXObject("Microsoft.XMLHTTP");
  18. } catch (e) {}
  19. }
  20. }
  21. if (!http_request) {
  22. alert('Cannot create XMLHTTP instance');
  23. return false;
  24. }
  25. http_request.onreadystatechange = alertContents;
  26. http_request.open('GET', url + parameters, true);
  27. http_request.send(null);
  28. }
  29.  
  30. function alertContents() {
  31. if (http_request.readyState == 4) {
  32. if (http_request.status == 200) {
  33. //alert(http_request.responseText);
  34. result = http_request.responseText;
  35. document.getElementById('myspan').innerHTML = result;
  36. } else {
  37. alert('There was a problem with the request.');
  38. }
  39. }
  40. }
  41.  
  42. function get(obj) {
  43. var getstr = "?";
  44. for (i=0; i<obj.childNodes.length; i++) {
  45. if (obj.childNodes[i].tagName == "INPUT") {
  46. if (obj.childNodes[i].type == "text") {
  47. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  48. }
  49. if (obj.childNodes[i].type == "checkbox") {
  50. if (obj.childNodes[i].checked) {
  51. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  52. } else {
  53. getstr += obj.childNodes[i].name + "=&";
  54. }
  55. }
  56. if (obj.childNodes[i].type == "radio") {
  57. if (obj.childNodes[i].checked) {
  58. getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  59. }
  60. }
  61. }
  62. if (obj.childNodes[i].tagName == "SELECT") {
  63. var sel = obj.childNodes[i];
  64. getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
  65. }
  66.  
  67. }
  68. makeRequest('get.php', getstr);
  69. }
  70.  
  71.  
  72. <input type="button" name="button" value="GET test.html"
  73. onclick="javascript:makeRequest('test.html', '');">
  74. <br><br>
  75. <input type="button" name="button" value="GET get.php?test=2"
  76. onclick="javascript:makeRequest('get.php', '?test=2');">
  77. <br><br>
  78.  
  79.  
  80. <form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">
  81. <input type="text" name="myfield" value="teststring"><br>
  82. <input type="radio" name="myradio" value="0" checked> 0
  83. <input type="radio" name="myradio" value="1"> 1<br>
  84. <input type="checkbox" name="mycheck1" value="1"> 1
  85. <input type="checkbox" name="mycheck2" value="2"> 2
  86. <input type="checkbox" name="mycheck3" value="3"> 3
  87. <input type="checkbox" name="mycheck4" value="4"> 4
  88. <input type="checkbox" name="mycheck5" value="5"> 5
  89. <br>
  90. <select name="myselect">
  91. <option value="1">1</option>
  92. <option value="2">2</option>
  93. <option value="3">3</option>
  94. <option value="4">4</option>
  95. <br>
  96. <input type="button" name="button" value="Submit"
  97. onclick="javascript:get(this.parentNode);">
  98. <input type="submit" name="button" value="Normal Submit Button">
  99. </form>
  100.  
  101. <br><br>
  102. Server-Response:<br>
  103. <span name="myspan" id="myspan"></span>


w konsoli błędów jest napisane:

Ostrzeżenie: reference to undefined property obj.childNodes[i].tagName

mogę liczyć na pomoc ?
Go to the top of the page
+Quote Post
hiszpanespaniol
post
Post #2





Grupa: Zarejestrowani
Postów: 213
Pomógł: 39
Dołączył: 7.04.2008
Skąd: 3city

Ostrzeżenie: (0%)
-----


może to i banalne, ale nie może wysłać żądania. czy na pewno testujesz to na serwerze? z parserem php i w ogóle. może w tym problem? kod na stronie do której podałeś link jest identyczny więc powinien działać.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 13:36