Ajax - 500 内部服务器错误

Ajax - 500 Internal Server Error(Ajax - 500 内部服务器错误)
本文介绍了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 内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)