Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法在jquery函数中指定刷新我的div的确切目标_Javascript_Jquery_Struts2_Struts Config - Fatal编程技术网

Javascript 无法在jquery函数中指定刷新我的div的确切目标

Javascript 无法在jquery函数中指定刷新我的div的确切目标,javascript,jquery,struts2,struts-config,Javascript,Jquery,Struts2,Struts Config,先生, 当我点击“Rename Day button”时,jquery popop日历会出现在我的屏幕上,一旦我点击它的submit按钮,它就会转发到我的页面,但不会刷新确切的div。。我不知道应该在哪里指定用于刷新特定div的div目标 用于提交的jquery函数 struts.xml /jsps/usertemplaterlightmiddlediv.jsp 扩展“OK按钮”的功能以停止默认表单提交行为,然后创建一个ajax函数连接到XML文件,返回数据,然后将数据插入ID为userTem

先生, 当我点击“Rename Day button”时,jquery popop日历会出现在我的屏幕上,一旦我点击它的submit按钮,它就会转发到我的页面,但不会刷新确切的div。。我不知道应该在哪里指定用于刷新特定div的div目标

用于提交的jquery函数 struts.xml

/jsps/usertemplaterlightmiddlediv.jsp

扩展“OK按钮”的功能以停止默认表单提交行为,然后创建一个ajax函数连接到XML文件,返回数据,然后将数据插入ID为userTemplateRightmiddlediv的元素的.html()中

function okButton(){
  $("#formId").submit(function(e){ //'e' for 'event'
    e.preventDefault();//stop the page from refreshing
    $.ajax({
      url: 'Struts2 URL Here',
      dataType: 'xml',
      success: function(xml){
        //function(xml) represents an object returned from our XML file, we can work with it however we want by using normalized jquery procedures
        $("#userTemplateRightmiddlediv").html(xml);
      }
    });
  });
}
编辑


更改为反映Struts 2的可移植性。

您试图触发两次提交。$是一个返回对象的函数。'“提交”是该对象的一种方法。如果jquery对象持有一个表单,这就像按下表单上的submit按钮,页面就会刷新,剩下的所有代码都无关紧要。您尝试提交两次,但$(此)。提交没有实际意义

如果非要我猜的话,也许你想要更像这样的东西:

$('#formId').submit( function(e){
    e.preventDefault(); // stops the page from reloading
    //maybe ajax or something else to change this div you're talking about.
} )

这看起来不错,为了帮助您以一种可移植的方式构造正确的url,请使用struts2 url标记来代替此答案中的“location/to/my/file.xml”。还可以使用struts2 json插件,使用json而不是xml。
function okButton(){
  $("#formId").submit(function(e){ //'e' for 'event'
    e.preventDefault();//stop the page from refreshing
    $.ajax({
      url: 'Struts2 URL Here',
      dataType: 'xml',
      success: function(xml){
        //function(xml) represents an object returned from our XML file, we can work with it however we want by using normalized jquery procedures
        $("#userTemplateRightmiddlediv").html(xml);
      }
    });
  });
}
$('#formId').submit( function(e){
    e.preventDefault(); // stops the page from reloading
    //maybe ajax or something else to change this div you're talking about.
} )