Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.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将中的唯一数字转换为字符串_Javascript_Jquery_Cordova - Fatal编程技术网

如何使用javascript将中的唯一数字转换为字符串

如何使用javascript将中的唯一数字转换为字符串,javascript,jquery,cordova,Javascript,Jquery,Cordova,我无法使用AJAX向服务URL参数发送值。该值为6946602c34d442a6。我正在将此值发送到以下URL: $'btn'。单击函数{ var userName=$'userName'.val; var password=$'password'.val; var lg_dev=device.uuid; var lginfo=lg_dev.toString; var urlInfo=http://xxx.xxx.xxx.xxx:xx/Service1.svc/log; $.ajax{ 键入:“

我无法使用AJAX向服务URL参数发送值。该值为6946602c34d442a6。我正在将此值发送到以下URL:

$'btn'。单击函数{ var userName=$'userName'.val; var password=$'password'.val; var lg_dev=device.uuid; var lginfo=lg_dev.toString; var urlInfo=http://xxx.xxx.xxx.xxx:xx/Service1.svc/log; $.ajax{ 键入:“GET”, url:urlInfo, 数据:uid=+userName+&pwd=+password+&DeviceId=+lginfo+, 成功:functionresp{ var data1=响应; console.logdata1; }, 错误:functione{ //SpinnerPlugin.activityStop; window.plugins.toast.showlongbottom无效数据; //SpinnerPlugin.activityStop; } }; }; 直到数据部分的数据得到,但后来它直接指向错误部分,并在调试时指向错误部分。它正在显示此错误:

在使用邮递员时,我可以得到当天的信息,下面是我登录时使用的数据

    {
    "Id": "2",
    "DeviceID": "6956303c32d442a1",
    "Extension": "@nazu.nz",
    "Name": "nazu",
    "Password": "nazu",
    "UserName": "mxa",
    "sno": 3,
    "status": true
}
在调试过程中,它还将转到jquery文件

while ( ( handleObj = matched.handlers[ j++ ] ) &&
                !event.isImmediatePropagationStopped() ) {

                // Triggered event must either 1) have no namespace, or 2) have namespace(s)
                // a subset or equal to those in the bound event (both can have no namespace).
                if ( !event.rnamespace || event.rnamespace.test( handleObj.namespace ) ) {

                    event.handleObj = handleObj;
                    event.data = handleObj.data;

                    ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle ||
                        handleObj.handler ).apply( matched.elem, args );

                    if ( ret !== undefined ) {
                        if ( ( event.result = ret ) === false ) {
                            event.preventDefault();
                            event.stopPropagation();
                        }
                    }
                }
            }
在这之后,它将

// Call the postDispatch hook for the mapped type
    if ( special.postDispatch ) {
        special.postDispatch.call( this, event );
    }

    return event.result;
},
callback = function( type ) {
                    return function() {
                        if ( callback ) {
                            callback = errorCallback = xhr.onload =
                                xhr.onerror = xhr.onabort = xhr.onreadystatechange = null;

                            if ( type === "abort" ) {
                                xhr.abort();
                            } else if ( type === "error" ) {

                                // Support: IE9
                                // On a manual native abort, IE9 throws
                                // errors on any property access that is not readyState
                                if ( typeof xhr.status !== "number" ) {
                                    complete( 0, "error" );
                                } else {
                                    complete(

                                        // File: protocol always yields status 0; see #8605, #14207
                                        xhr.status,
                                        xhr.statusText
                                    );
                                }
                            } else {
                                complete(
                                    xhrSuccessStatus[ xhr.status ] || xhr.status,
                                    xhr.statusText,

                                    // Support: IE9 only
                                    // IE9 has no XHR2 but throws on binary (trac-11426)
                                    // For XHR2 non-text, let the caller handle it (gh-2498)
                                    ( xhr.responseType || "text" ) !== "text"  ||
                                    typeof xhr.responseText !== "string" ?
                                        { binary: xhr.response } :
                                        { text: xhr.responseText },
                                    xhr.getAllResponseHeaders()
                                );
                            }
                        }
                    };
                };
然后去

// Call the postDispatch hook for the mapped type
    if ( special.postDispatch ) {
        special.postDispatch.call( this, event );
    }

    return event.result;
},
callback = function( type ) {
                    return function() {
                        if ( callback ) {
                            callback = errorCallback = xhr.onload =
                                xhr.onerror = xhr.onabort = xhr.onreadystatechange = null;

                            if ( type === "abort" ) {
                                xhr.abort();
                            } else if ( type === "error" ) {

                                // Support: IE9
                                // On a manual native abort, IE9 throws
                                // errors on any property access that is not readyState
                                if ( typeof xhr.status !== "number" ) {
                                    complete( 0, "error" );
                                } else {
                                    complete(

                                        // File: protocol always yields status 0; see #8605, #14207
                                        xhr.status,
                                        xhr.statusText
                                    );
                                }
                            } else {
                                complete(
                                    xhrSuccessStatus[ xhr.status ] || xhr.status,
                                    xhr.statusText,

                                    // Support: IE9 only
                                    // IE9 has no XHR2 but throws on binary (trac-11426)
                                    // For XHR2 non-text, let the caller handle it (gh-2498)
                                    ( xhr.responseType || "text" ) !== "text"  ||
                                    typeof xhr.responseText !== "string" ?
                                        { binary: xhr.response } :
                                        { text: xhr.responseText },
                                    xhr.getAllResponseHeaders()
                                );
                            }
                        }
                    };
                };

这应该会澄清一些事情:

$('#btn').click(function() {
  var userName = $('#Username').val();
  var password = $('#password').val();
  var lg_dev = device.uuid;
  var lginfo = lg_dev.toString();
  var urlInfo = "http://xxx.xxx.xxx.xxx:xx/Service1.svc/log";

  $.ajax({
    type: 'GET',
    url: urlInfo,
    data: {
      uid: userName,
      pwd: password,
      DeviceId: lginfo
    },
    success: function(data, status, xhr) {
      console.log(arguments);

      if (data) {
        var data1 = data;
      } else {
        console.log('Server sent an empty response.');
      }
    },
    error: function(xhr, status, error) {
       console.log('Ajax failed', arguments);
      // SpinnerPlugin.activityStop();
      window.plugins.toast.showLongBottom("Invalid Data");
      // SpinnerPlugin.activityStop();
    }
  });
});

所有内容都在HTTP请求中作为字符串发送,因此类型转换不是您的问题。给出错误消息后,您似乎只是缺少了resp属性somwhere。@Rory McCrossan但当我与postman检查url时,我能够获得数据是否有其他使用变量名resp的代码?听起来这可能是CORS的问题。请求完成后,请检查控制台是否有错误。您可能在成功匿名函数之外使用了resp。OP的$.ajax可以。@rrv您认为可以,但以字符串形式传入的数据应该进行编码,在他的情况下不是,他还认为服务器会做出响应,但情况可能不是这样。您是正确的,但这并不能回答OP的问题。@rrv他说他不能向服务器发送值,用我的版本,他应该能够向服务器发送值。如果他不这样做,那么他将返回控制台,返回他在控制台中收到的最终错误或消息