0

我创建了一个小型 Web 应用程序,我正在尝试连接到我的 Web 服务。出于某种原因,我收到错误“200”。

功能很简单:
1 ) 用户在 Home.html 页面上输入一个值(产品编号)。
2 ) 调用服务并根据输入的值执行搜索。
3 ) 如果找到结果,在 SearchResult.html 页面输出产品编号。

主页.html

<!DOCTYPE html>
<!--[if IEMobile 7 ]>    <html class="no-js iem7"> <![endif]-->
<!--[if (gt IEMobile 7)|!(IEMobile)]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="cleartype" content="on">

    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/touch/apple-touch-icon-144x144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/touch/apple-touch-icon-114x114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/touch/apple-touch-icon-72x72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="img/touch/apple-touch-icon-57x57-precomposed.png">
    <link rel="shortcut icon" href="img/touch/apple-touch-icon.png">

    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileImage" content="img/touch/apple-touch-icon-144x144-precomposed.png">
    <meta name="msapplication-TileColor" content="#222222">

    <script src="js/vendor/modernizr-2.6.1.min.js"></script>    
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js">    </script>

</head>
<body>

    <header class="Navigation">            
        <div class="headerImage"><img src="images/logo-small.png" alt="Home"/</div>        
    </header>

    <div id="product" class="Banner">
        Product Search
    </div>

       <br />
        <div class="nine-tenths">
            Please enter a product number.
        </div>

            <input id="productNum" class="productNum" type="text" placeholder="Enter Product Number"/>           

        <br />                                 

        <button type="button" id="btnSearch" onclick="btnSearch()">Search</button>   

        <script src="js/main.js"></script>
</body>

主.JS

function btnSearch() {
//  document.location.href = 'SearchResult.html';

var productNum= $("#productNum").val(); 
alert(productNum);

var ajaxSearch = "http://localhost:8008/Product/ProductList/GetProduct.php?prod_num?" + productNum;
alert(ajaxSearch);

$.ajax(ajaxSearch,

{
    beforeSend: function (xhr) {
    // $.mobile.showPageLoadingMsg();
},

complete: function () {
// $.mobile.hidePageLoadingMsg();
},
    contentType: 'application/json',
    dataType: 'jsonp',
    jsonp: 'callback',
    type: 'GET',
    error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.status);
    alert(xhr.responseText);
    //alert(thrownError);
},
success: function (data) {
    var result = data.GetEmployeeListingResult;

    $.each(result, function (index, output) {
        $('#EmployeeList').append('<li> <a href=SearchResult.html?productNum=' + output.prod + '> </a>   .....</li>');
    });

    //$('#EmployeeList').listview('refresh');
}
}); 

}

搜索结果.html

<table style="width:100%;" class="searchResultFound">
        <tr>
            <td style="width: 10%;">
                <img src="images/resultFound.png" align="left">
            </td>
            <td>
                <input id="productNum" type="text" class="no-outline " disabled="disabled" value="">
                <label>Was found</label>
            </td>
        </tr>
    </table>

    <table style="width:100%;" class="searchResultNotFound">
        <tr>
            <td style="width: 10%;">
                <img src="images/resultNotFound.png" align="left">
            </td>
            <td>
                <input id="productNum" type="text" class="no-outline " disabled="disabled" value="">
                <label>Was not found</label>
            </td>
        </tr>
    </table>

我曾尝试使用此站点作为示例(为什么您可能会看到对 Employee 的引用):

http://wrvishnu.wordpress.com/2012/07/29/step-by-step-tutorial-restful-wcf-web-service-and-jquery-mobile/

谢谢

4

1 回答 1

0

main.js 中的 URL 声明错误.. 'prod_num',

使用“'GetProduct.php?prod_num=' + productNum”

而不是“'GetProduct.php?prod_num?' + 产品编号"

尝试使用这个:

var ajaxSearch = "http://localhost:8008/Product/ProductList/GetProduct.php?prod_num=" + productNum;
于 2013-05-31T10:07:46.770 回答