首页 \ 问答 \ Ajax请求未传递给控制器(Ajax request not passed to controller)

Ajax请求未传递给控制器(Ajax request not passed to controller)

我向控制器发送了一个AJAX请求。 这个开发在JSP和Spring环境中完成。 SimpleFormController被我正在使用的控制器覆盖。 使用JavaScript我创建对象并发送请求。 此请求未传递给控制器​​。 如果您对此问题有任何疑问,请帮助我。

发送请求的JavaScript代码。

function getStates(){
    var httpRequest;
    var country = document.getElementById('countryName');
    alert(country);
    var url = '/developer/register.htm';

    url = url + (url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true');

     if (window.ActiveXObject)
     {
         httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
     }
     else if (window.XMLHttpRequest)
     {
         httpRequest = new XMLHttpRequest();
     }

     httpRequest.open("GET", url, true);
     httpRequest.onreadystatechange = function() {processRequest(); };
     httpRequest.send(null);
}

function processRequest() {
    if(httpRequest.readyState == 4){
        alert("inside ready state");
        var response = http.responseText;
        document.getElementById('states').innerHTML = response;
    }
}

变量url以我在调度程序servlet中提到的方式给出。

浏览器在processRequest()函数中显示错误 ,告知未定义httpRequest。 但是,我在前面的行中没有得到这个错误 ,我在getStates()函数中使用了这个对象。 如果有人对此有所了解,请帮我解决这个问题。 在此先感谢并感谢您的支持。


I send an AJAX request to my controller. This development done in JSP and Spring environment. SimpleFormController is overridden by the controller I'm using.

Using JavaScript I create the object and send the request. this request is not getting passed to controller.

JavaScript code which send the request.

function getStates(){
    var httpRequest;
    var country = document.getElementById('countryName');
    alert(country);
    var url = '/developer/register.htm';

    url = url + (url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true');

     if (window.ActiveXObject)
     {
         httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
     }
     else if (window.XMLHttpRequest)
     {
         httpRequest = new XMLHttpRequest();
     }

     httpRequest.open("GET", url, true);
     httpRequest.onreadystatechange = function() {processRequest(); };
     httpRequest.send(null);
}

function processRequest() {
    if(httpRequest.readyState == 4){
        alert("inside ready state");
        var response = http.responseText;
        document.getElementById('states').innerHTML = response;
    }
}

Variable url is given in the way how I have mentioned in dispatcher servlet.

The browser shows an error in processRequest() function telling that httpRequest is not defined. but, I don't get this error in the previous lines. I use this object in getStates() function.


原文:https://stackoverflow.com/questions/8118690
更新时间:2022-01-04 07:01

最满意答案

我认为错误在这里:

while(ptr->next != NULL){
    ptr = ptr->next;
    count++;
}

假设你的链表中有2个元素。 然后while循环只迭代一次, count将为1.当你进入for循环时,它也只会迭代一次,这意味着你将正确地重新分配新头的指针,而不是第二个元素(以前的头脑)。

如果将count初始化为1而不是0,则应该正确反映链表中元素的数量,并且for循环应该正确执行。

编辑:您还必须稍微重构for循环以避免列表末尾的段错误:

Node* temp;

for (int i = 0; i < count; i++)
{
    temp = ptr->next;
    ptr->next = ptr->prev;
    ptr->prev = temp;
    ptr = ptr->next;
}

I think the error is here:

while(ptr->next != NULL){
    ptr = ptr->next;
    count++;
}

Let's say your linked list has 2 elements in it. Then that while loop will only iterate once, and count will be 1. When you get down to the for loop, it will also only iterate once, which means you will correctly reassign the pointers for the new head, but not the second element (previously the head).

If you initialize count to 1 instead of 0, it should correctly reflect the number of elements in the linked list and the for loop should execute correctly.

Edit: You will also have to restructure your for loop slightly to avoid a segfault at the end of the list:

Node* temp;

for (int i = 0; i < count; i++)
{
    temp = ptr->next;
    ptr->next = ptr->prev;
    ptr->prev = temp;
    ptr = ptr->next;
}

相关问答

更多
  • 您正在从tailInsert返回temp(最后一个节点)并分配给head。 如果要插入尾部,请不要更改头指针。 void tailInsert(node *head, int data) { if(head->next == NULL) { node *temp; temp = createNode(data); temp->next = NULL; temp->prev = head; head->next = temp; ...
  • 我认为错误在这里: while(ptr->next != NULL){ ptr = ptr->next; count++; } 假设你的链表中有2个元素。 然后while循环只迭代一次, count将为1.当你进入for循环时,它也只会迭代一次,这意味着你将正确地重新分配新头的指针,而不是第二个元素(以前的头脑)。 如果将count初始化为1而不是0,则应该正确反映链表中元素的数量,并且for循环应该正确执行。 编辑:您还必须稍微重构for循环以避免列表末尾的段错误: Node* temp ...
  • 它与单链表的不同之处在于节点可以插入任何地方,不仅仅是在头部之后或尾部之后使用可用的下一个和上一个节点,而在单链表中,这个插入列表中的任何地方都是不可能的? 这是错的。 您可以在单个链接列表的中间插入节点就好了。 唯一的区别是双链表更容易导航,因为您可以从任何给定节点向前和向后移动它。 如果想要在双向链表中插入节点,那么默认参数应该是待插入节点之后的节点或待插入节点之前的节点? 这完全取决于您使用列表的内容。 链接列表由于其随机访问性能差而不是真正的通用数据结构。 因此,它们通常仅用于迭代遍历列表的算法,并 ...
  • private void DeleteItemHelper(final int indexToDelete, int curIndex, DLLNode curNode) { if (curIndex == indexToDelete) { // Handle removing a node with both a previous and next nodes. } else { DeleteItemHelper(indexToDelete, cu ...
  • 取决于链表的具体实现。 两种方式都可以工作,但有额外的“头/尾”元素大大简化了插入/删除等许多操作的实现(因为你总是可以确定会有下一个/前一个元素,节省了大量的条件代码处理列表的开始/结束)。 由于您将问题标记为Java,我建议您查看java.util.LinkedList的JDK源代码。 您将发现在此特定实现中,head和tail不引用元素。 如果你真的想要理解额外的头/尾节点的优势,如果你自己实现一个简单的双链表来亲自体验插入/删除方法的复杂性差异,那么它可能是最有启发性的。 在允许指针算术的其他语言中 ...
  • 您的代码没有设置足够的指针。 通常,您必须确保新节点的prev是正确的; 它是next是正确的; 前一个条目的next是正确的; 并且下一个条目的prev是正确的(如果前一个或下一个条目为NULL,则要小心)。 假设全局变量是: value *entry_head = NULL; value *entry_tail = NULL; 然后插入新value *ent (已经用值初始化)的代码是: if (entry_head == NULL) { assert(entry_tail == NULL); ...
  • 让我们一次尝试一下几行代码。 Node temp=head; head=tail; tail=temp; 这里我们只是设置一些变量。 我们正在交换头部,指向尾部和尾部。 现在我们定义我们的起始节点。 这是我们的新头,曾经是尾巴。 Node p=head; //create a node and point to head while(p!=null) { temp=p.next; 在这一点上,这就是我们所看到的(注意:如果这是第一次迭代, next将指向null,但这并不重要,只是假设A在 ...
  • 在代码中,newTail总是一个接一个。 在while循环中,newTail-> next设置为iter,iter-> prev设置为newTail。 哪个没效果。 也许这个图表会有所帮助 尝试这个。 它循环遍历列表,并为每个节点交换next和prev指针。 (这可能不是最有效的算法。) Node* Reverse2(Node* head) { if (head == nullptr) {return head;} Node *iter = head; Node *tail = nullptr ...
  • 你想删除列表的头部并使其成为新的尾部。 你应该弄清楚如何在脑海中做到这一点,代码将是一个逻辑表示。 删除列表的头部。 新头成为下一个项目。 现在,被删除的物品是独立的; 它之后什么也没有。 将节点放在列表的末尾。 新尾部成为该节点。 正如您所看到的,您现在的代码并不完全如此。 一次完成一个步骤: 那么,第1步: Node node = head; head = head.next; // <- remove head, new head becomes next item 然后,第2步: node.nex ...
  • if(head == null) { head = new CardInfoNode(); head.setCardInfo(info); head.setNext(tail); tail.setPrev(node) // here lies the problem. tail must be set to something // to make it doubly-lin ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)