如何在cordova android中向服务器发送json数据

如何在cordova android中向服务器发送json数据,json,cordova,Json,Cordova,hi frnd form最近2天我试图将JSON数据发送到服务器,但不工作我正在发布我的js文件,并检查是否有任何错误。我尝试使用xmlHttprequest发送json数据。如果我需要做任何其他功能和更改,请告诉我。我正在eclipse中开发cordova项目,如果还有其他东西和文件需要更改,请告诉我 这是我的js文件,点击注册按钮,我调用这个方法 function get() { alert("function is called");

hi frnd form最近2天我试图将JSON数据发送到服务器,但不工作我正在发布我的js文件,并检查是否有任何错误。我尝试使用xmlHttprequest发送json数据。如果我需要做任何其他功能和更改,请告诉我。我正在eclipse中开发cordova项目,如果还有其他东西和文件需要更改,请告诉我 这是我的js文件,点击注册按钮,我调用这个方法

        function get() {
            alert("function is called");
             var name_field_value=document.getElementById("name_field").value;
            var email_field_value=document.getElementById("email_field").value;
            var password_field_value=document.getElementById("password_field").value;
            var phone_field_value=document.getElementById("phone_field").value;

             var JSONdata= {
                    "name": name_field_value,
                    "mobile_number": phone_field_value,
                    "email": email_field_value,
                    "password": password_field_value
                }
                var request = new XMLHttpRequest();
                request.open("POST", "http://www.jiyonatural.com/AccountManagements/insert_new_user", true);
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        alert(request.status);//this alert is working and getting 0 status
                        if (request.status == 200 || request.status == 0) {
                            // -> request.responseText <- is a result
                            /*var tweets = JSON.parse(request.responseText);*/
                            alert(request.responseText);//this alert is not working// 
                            //if i make other alert then it works
                        }else{
                            alert("function is called3");}
                    }
                }
                request.send(JSON.stringify(JSONdata));
            }

看来你的问题不完整。 根据我的经验,错误可能在于服务器代码

您应该在jquery中使用ajax方法与服务器通信。它比XMLhttpRequest更容易