Ajax - 500 内部服务器错误

时间:2023-05-15
本文介绍了Ajax - 500 内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在努力为这个项目学习 AJAX.我有一个网站加载患者正在服用的药物.

I am trying to learn AJAX for this project at work. I have a site that loads medications that a patient is taking.

我递归地调用这个 AJAX 函数,以便它会附加一个新表,其中包含一种药物和 7 天的历史记录.我在让代码在 FF 和 IE 中执行时遇到问题.在镀铬中工作得很好.我有显示 xmlhttp.status 的警报,这就是我得到的:

I call this AJAX function up recursively so that it will append a new table containing a single medication and 7 days worth of history. I am having issues getting the code to execute in FF and IE. Works perfectly fine in chrome. I had alerts displaying the xmlhttp.status and this is what I got:

xmlhttp.status==500(内部服务器错误).

xmlhttp.status==500 (internal server error).

我注释掉了我所有的递归,所以它被缩小到这个小代码.(x 跟踪药物的数量,所以我知道什么时候停止)

I commented out all of my recursion so it is narrowed down to this tid bit of code. ( x keeps track of the number of meds so i know when to stop)

function LoadMeds()


  if ( x == MaxMedCount )
  {
      document.getElementById("the_day").value = parseInt(document.getElementById("the_day").value)+7; 
  }
  if ( x == (MaxMedCount - 1) )
  {
      document.getElementById("x").value = x + 1;
      show();
  }
  else
  { 

      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function()
      {
          try 
          {      
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
              {     
                  var div = document.createElement('div');
                  div.innerHTML= xmlhttp.responseText;
                  document.getElementById('MedTable').appendChild(div);
                  document.getElementById("the_med_").value = the_med_;

              }

          }
          catch(e)
          {
              alert("Error");  
          }
      }
      xmlhttp.open("GET","URL with variables passed",true);
      xmlhttp.send();     
      document.getElementById("x").value = x + 1;
  } 

如果需要更多代码,请告诉我.

if more code is needed just let me know.

推荐答案

500 (internal server error) 表示服务器端出现问题.这可能是几件事,但我会首先验证 URL 和参数是否正确.另外,请确保处理请求的任何东西都期望请求是 GET 而不是 POST.

The 500 (internal server error) means something went wrong on the server's side. It could be several things, but I would start by verifying that the URL and parameters are correct. Also, make sure that whatever handles the request is expecting the request as a GET and not a POST.

了解更多信息的一种有用方法是使用 Fiddler 之类的工具让您查看所有 HTTP 请求和响应,以便准确查看您发送的内容以及服务器的响应.

One useful way to learn more about what's going on is to use a tool like Fiddler which will let you watch all HTTP requests and responses so you can see exactly what you're sending and the server is responding with.

如果您没有令人信服的理由来编写自己的 Ajax 代码,那么最好使用一个为您处理 Ajax 交互的库.jQuery 是一种选择.

If you don't have a compelling reason to write your own Ajax code, you would be far better off using a library that handles the Ajax interactions for you. jQuery is one option.

这篇关于Ajax - 500 内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:使用 XMLHTTPRequest 进行基本身份验证 下一篇:responseXML 始终为空

相关文章