Ajax调用wcf服务无法正常工作

时间:2018-03-02 04:24:32

标签: javascript jquery json wcf

我写了一个返回json字符串的web服务。我试图从一个HTML页面调用此服务。但是ajax调用没有返回所需的结果。

调用服务的代码如下

<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
    url: "http://localhost:3292/examservice.svc/ExamQs"
}).then(function(data) {

   $('.question').append(data.Question);
   $('.answer').append(data.Answer1);
});
});
</script>

 <body>
    <div>
        <p class="question">The Question is </p>
        <p class="answer">The Answer is </p>
    </div>
</body>

服务的输出是

[{"Answer1":"This is Answer1 of Question 1","Answer2":"This is Answer2 of Question 1","Answer3":"This is Answer3 of Question 1","Answer4":"This is Answer4 of Question 1","Correct":1,"Question":"This is the Question no 1"}]

0 个答案:

没有答案