简体   繁体   English

带有Ajax的jQuery Mobile到远程服务器的调用不起作用

[英]jQuery Mobile with Ajax call to remote server not working

I am trying the following code to call .asmx webserivce, however, its returning [object Object] 我正在尝试以下代码来调用.asmx webserivce,但是,其返回的[object Object]

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>   </title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>
<link rel="stylesheet" href="icon.css" type="text/css">
<script type="text/javascript" charset="utf-8" src="js/wormhole.js"></script>
<script type="text/javascript">
document.addEventListener(
        "backbutton",
        function()
        {
            mosync.app.exit();
        },
        true);

        $(document).bind("mobileinit",function(){
            $.mobile.page.prototype.options.addBackBtn = true;  
    $.mobile.allowCrossDomainPages=true;
    $.support.cors= true;
  });

  $(document).ready(function(e) {
    $.ajax({
    url: 'http://webservice.gkg4.com/Test.asmx/HelloWorld',
    type: 'POST',
    crossDomain: true,
    contentType: "application/json; charset=utf-8",

    dataType: 'json',
    success: function(result){
        alert(result);
    },
    error: function(result){
        alert(result);
    }
});
});
    </script>

</head>

<body>
<div data-role="page" id="home">
  <div data-role="header">
    <img src="image/png/chat.png" alt="image">
    <a href="#popupPanel" data-rel="popup" data-role="button" class="ui-btn  ui-icon-grid ui-btn-icon-left ui-btn-right ui-btn-icon-notext">Menu</a>

<div data-role="popup" id="popupPanel" >
<ul data-role="listview" data-inset="true" style="min-width:210px;" data-theme="b">
                    <li data-role="divider" data-theme="a">Menu</li>
                    <li><a href="aboutus.html">About Us</a></li>
                    <li><a href="contactus.html">Contact Us</a></li>
            <li><a href="#" id="chat" rel="external" >Live Chat</a></li>
            <li><a href="#" onclick="mosync.app.exit();">Exit</a></li>
                </ul>    
</div>
  </div>
  <div data-role="content" data-theme="b">
  <div style="text-align:center">

  </div>
  <h4><center> Member's Login</center></h4>
  </div>

  <div data-role="footer" data-position="fixed">
<div data-role="navbar" data-iconpos="left">
    </div>
  </div>
</div>
</body>
</html>

The URL for webservice is live so you can check the same at your end. Web服务的URL是实时的,因此您可以在末尾对其进行检查。 Any help appreciated. 任何帮助表示赞赏。 Code in in document.Ready section 文档中的代码。就绪部分

Is the page where you are calling from also from webservice.gkg4.com? 也是从webservice.gkg4.com呼叫的页面吗? If not, it is illegal to call ajax from a different domain, and the alert that you are seeing is actually from the error handler. 如果不是,则从另一个域调用ajax是非法的,并且您看到的警报实际上是来自错误处理程序的。

Another problem is that the contentType is json, whereas the web service is returning XML. 另一个问题是contentType为json,而Web服务正在返回XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM