Ajax XMLHttpRequest POST到我的webservice [英] Ajax XMLHttpRequest POST to my webservice

查看:98
本文介绍了Ajax XMLHttpRequest POST到我的webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的localhost上有以下XML,URL为:`http:// localhost:8080 / manager / rest / beanRepresentation /`



XML的外观像这样:



Currently I have the following XML on my localhost, URL being: `http://localhost:8080/manager/rest/beanRepresentation/`

XML looks like this:

<collection>
 <beanRepresentation>
 <topY>0</topY>
 <leftX>0</leftX>
 </beanRepresentation>


//more.. beans.
</collection>





我希望能够通过发布用户的新坐标来更改topY和leftX字段,所以下次解析和显示此XML时,它将显示先前保存的位置。



我正在阅读以下内容:





I want to be able to change the topY and leftX field by posting new coordinates from the user, so next time this XML is being parsed and displayed, it will display the previously saved position.

I am reading it like the following:

< script>
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    			xmlhttp=new XMLHttpRequest();
    		} else {// code for IE6, IE5
    			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    
    		xmlhttp.open("GET","http://localhost:8080/manager/rest/beanRepresentation/",false);
    		xmlhttp.send();
    		xmlDoc=xmlhttp.responseXML; 

     // Code here ... do stuff, display it on the page

     // this particular function moves each box displayed on the page, also makes it draggable, and I need to save these new coordinates of each box being dragged.
    $('.normal').draggable({//drag
    			stop: function() {//on stop
    				var t = parseInt($(this).position().top),//get top
            		l = parseInt($(this).position().left);//get left
    			// So here, t and l are my top and left that I need to save it back to the database.
    			}

         // I added the following, to post it back to the database after EACH drag: 
    
         xmlhttp.open("POST","http://localhost:8080/manager/rest/beanRepresentation/",true);
         xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
         xmlhttp.send("   ");  // what do I put in here?
        		});
    </script>





另外,因为我不想拨打电话每次拖动一个框时都会发布POST,是否更好地创建一个保存按钮,并且只有在单击按钮时才进行POST?如果是这样,我如何跟踪被拖动的所有方框并仅发布那些后面的



Also, since I dont want to make a call to POST each time a box is dragged around, is it better to make a save button, and only POST when the button is clicked? If so, how do I keep track all the boxes being dragged and POST only those back

推荐答案

('。normal')。draggable({//拖动
stop:function(){// on stop
var t = parseInt(
('.normal').draggable({//drag stop: function() {//on stop var t = parseInt(


(this).position()。top),// get top
l = parseInt(
(this).position().top),//get top l = parseInt(


(this).position()。left); //得到左边
//所以这里,t和l是我需要的顶部和左边我需要的将它保存回数据库。
}

//我添加了以下内容,在每次拖动后将其发回数据库:

xmlhttp.open (POST,http:// localhost:8080 / manager / rest / beanRepresentation /,true);
xmlhttp.setRequestHeader(Content-type,application / x-www-form-urlencoded );
xmlhttp.send(); //我在这里放什么?
});
< / script >
(this).position().left);//get left // So here, t and l are my top and left that I need to save it back to the database. } // I added the following, to post it back to the database after EACH drag: xmlhttp.open("POST","http://localhost:8080/manager/rest/beanRepresentation/",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send(" "); // what do I put in here? }); </script>





另外,因为我不想拨打电话每次拖动一个框时都会发布POST,是否更好地创建一个保存按钮,并且只有在单击按钮时才进行POST?如果是这样,我如何跟踪被拖动的所有方框并仅对那些后方进行POST



Also, since I dont want to make a call to POST each time a box is dragged around, is it better to make a save button, and only POST when the button is clicked? If so, how do I keep track all the boxes being dragged and POST only those back


这篇关于Ajax XMLHttpRequest POST到我的webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆