Return JSONP in proper format WCF

前端 未结 2 1462
梦毁少年i
梦毁少年i 2020-12-19 10:29

I\'m trying to output a correctly wrapped JSONP value for jQuery to consume.

The output I\'m looking for is:

jsoncallback({\"Status\": \"OK\"})
         


        
2条回答
  •  甜味超标
    2020-12-19 11:21

    You need to eval the output from your WCF call. See this fiddle.

    You're getting a string back from your WCF call. You essentially need to compile it and then execute it.

    Here's the code from the fiddle:

    function jsonCallback(obj){
        alert(obj.Status);
    }
    
    $(document).ready(function(){
        var js = "jsonCallback({'Status':'OK'})";
        eval(js);
    });​
    

    The js variable is your output from the WCF call. As soon as I eval it, it will compile and execute.

提交回复
热议问题