简体   繁体   English

重新加载页面部分时的 AJAX 请求

[英]AJAX Request while reloading Page partial

I'm new registered but was a quiet reader for years.我是新注册的,但多年来一直是一个安静的读者。 To this Point I have found the answer for all my questions by searching Stack Overflow, but now I have to ask...到目前为止,我已经通过搜索 Stack Overflow 找到了我所有问题的答案,但现在我必须问......

I'm new with AJAX and I am building a test ap for a AJAX Request.我是 AJAX 的新手,我正在为 AJAX 请求构建一个测试应用程序。 I followed the example from this page.我按照此页面中的示例进行操作。 http://www.w3schools.com/php/php_ajax_database.asp http://www.w3schools.com/php/php_ajax_database.asp

Info about my test ap: Its all about programming a wizard.关于我的测试 ap 的信息:这完全是关于对向导进行编程。 This code is from my "wizzard.php".这段代码来自我的“wizzard.php”。

The index.php is loading the "wizzard.php" via JQUERY in a Content div with some id. index.php 正在通过 JQUERY 在具有某些 id 的 Content div 中加载“wizzard.php”。 So all the includes for the Framework etc. are in the index.php.所以框架等的所有包含都在 index.php 中。 So far... The wizard works and is shown correctly in the browser.到目前为止... 该向导可以正常工作并在浏览器中正确显示。

now the Problem: The wizard itself has a button "Next".现在的问题:向导本身有一个按钮“下一步”。 If you click it you see Another "Page" from the wizard (Step).如果单击它,您会看到向导中的另一个“页面”(步骤)。 html looks like this: html看起来像这样:

    <div id="wiz1step3">

      <h4 class="widgettitle">Step 3: Overview</h4>
      <div class="par terms" style="padding: 0 20px;">
        <p>Hier werden zusammenfassend.</p>
        <p>Alle Informationen gesammelt die das Hinzufügen betreffen</p>
        <div id="DeviceTypeIdHint"><b>DeviceTypeID will be listed here...</b>
        </div>

        <p>
          <input type="checkbox" />I agree with the terms and agreement...</p>
      </div>

So I have a "Div Hint" like in the Example.所以我有一个像示例中的“Div Hint”。 This is where the code from AJAX Request should be showed.这是应该显示来自 AJAX 请求的代码的地方。

On Page 1 from the wizard I have a dropbox which Shows some Items from the database.在向导的第 1 页上,我有一个 Dropbox,它显示数据库中的一些项目。 I am going to proceed the Name of the Item via AJAX to the database und my goal is to Show the item-database-id in the wizard on Page 3. (the pages are controlled with JQUERY)我将通过 AJAX 将项目名称处理到数据库中,我的目标是在第 3 页的向导中显示项目数据库 ID。(页面由 JQUERY 控制)

So I have a jQuery Function at wizzard.php which should do the AJAX-Voodoo Stuff.所以我在 wizzard.php 有一个 jQuery 函数,它应该做 AJAX-Voodoo 的东西。

It Looks like this:它看起来像这样:

    jQuery('.buttonNext').click(function(e) {
          //Hier kommt der AJAX Aufruf für das Besorgen der ID des        ausgewähltenDevices

          e.preventDefault();
          var deviceTypeModel = jQuery('#selection option:selected').text();

          if (deviceTypeModel == "") {
            document.getElementById("DeviceTypeIdHint").innerHTML = "Es wurde keine    ID Zugeordnet";
          } else {
            if (window.XMLHttpRequest) {
              //code for IE7+, Firefix, Chrome, Opera, Safari                 
              xmlhttp = new XMLHttpRequest();
            } else {
              // code for IE6, IE5
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlhttp.onreadystatechange = function() {
              alert(xmlhttp.readyState)
              if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("DeviceTypeIdHint").innerHTML = xmlhttp.responseText;
              }
            }

            xmlhttp.open("GET", "getDeviceTypeIdFromDeviceTypeModel.php?q=" + deviceTypeModel, true);
            xmlhttp.send;
          }

In the same direction like the index.php and the wizzard.php is "GetDeviceTypeIdFromDeviceTypeModel.php".与 index.php 和 wizzard.php 相同的方向是“GetDeviceTypeIdFromDeviceTypeModel.php”。 located.位于。 This is the file that should do the AJAX-Voodoo trick.这是应该执行 AJAX-Voodoo 技巧的文件。

It Looks like this:它看起来像这样:

<?php

    /* 
     * nimmt AJAX Anfragen entgegen und führt sie aus
     */
    include_once '\includes\DataAccess.php';

    $DataAccess = new DataAccess();
    $DeviceTypeNameFromRequest = $_GET['q'];
    $AJAX_DeviceTypeId = $DataAccess ->GetDeviceTypeIdForDeviceTypeModel($DeviceTypeNameFromRequest);
    echo $AJAX_DeviceTypeId;

I have debugged the JQUERY stuff until the Point我已经调试了 JQUERY 的东西,直到点

    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById("DeviceTypeIdHint").innerHTML = xmlhttp.responseText;
    }

The Problem is that the readyState is always 1. My xmlhttp.responseText is always empty.问题是 readyState 始终为 1。我的 xmlhttp.responseText 始终为空。

I can't figure out why this Request don't work.我不明白为什么这个请求不起作用。 The Div-Hint is not changing. Div-Hint 没有改变。

ps.附: sorry for this horrible formatting this is my first post... this grammar correction annoys me and I'm struggling with the "code snipped tool" XD抱歉这种可怕的格式,这是我的第一篇文章......这个语法更正让我很恼火,我正在努力使用“代码剪切工具”XD

问题是您使用的是xmlhttp.send而不是xmlhttp.send()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM