Javascript 在JSONP响应中使用函数和对象,是否有效?

Javascript 在JSONP响应中使用函数和对象,是否有效?,javascript,jquery,jsonp,Javascript,Jquery,Jsonp,我正在使用函数和JSONP(JSFIDLE作为证明:) 这是我的JSONP结果: jsonCallback({ response: { aVal: "val", aFunction: function() { console.log("I'm a function set in the JSONP result"); alert("I'm a function set in the JSONP result"

我正在使用函数和JSONP(JSFIDLE作为证明:)

这是我的JSONP结果:

jsonCallback({
    response: {
        aVal: "val",
        aFunction: function() {
            console.log("I'm a function set in the JSONP result");
            alert("I'm a function set in the JSONP result");
        }
    }
})
jQuery这样调用它:

(function($) {
var url = 'https://pastebin.com/raw.php?i=M3vFvkbG';

$.ajax({
    type: 'GET',
    url: url,
    async: false,
    jsonpCallback: 'jsonCallback',
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(json) {
       json.response.aFunction(); // <== note this one
    },
    error: function(e) {
       console.log(e.message);
    }
});

})(jQuery);
(函数($){
var url='1〕https://pastebin.com/raw.php?i=M3vFvkbG';
$.ajax({
键入:“GET”,
url:url,
async:false,
JSONPCCallback:'jsonCallback',
contentType:“应用程序/json”,
数据类型:“jsonp”,
成功:函数(json){

json.response.affunction();//如果使用“valid”,你的意思是它是正确的JSONP,那么不是。但是因为JSONP只是一个
脚本
请求,它会像你看到的那样工作。如果你要这样做,我只会请求一个脚本。谢谢你的回答。这难道不能解决
脚本
标记可能存在的跨域问题吗?是的,如果服务器发送JSONP,它就解决了这个问题。当然可以我们认为它是不安全的,因为任何发送的代码都是执行的,但是如果您信任源代码,那么它会有所帮助。