簡體   English   中英

帶有Ajax的jQuery Mobile到遠程服務器的調用不起作用

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

我正在嘗試以下代碼來調用.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>

Web服務的URL是實時的,因此您可以在末尾對其進行檢查。 任何幫助表示贊賞。 文檔中的代碼。就緒部分

也是從webservice.gkg4.com呼叫的頁面嗎? 如果不是,則從另一個域調用ajax是非法的,並且您看到的警報實際上是來自錯誤處理程序的。

另一個問題是contentType為json,而Web服務正在返回XML。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM