NSURLConnection使用GET请求调用javascript函数

时间:2014-03-27 01:01:49

标签: javascript ios nsurlconnection

我有NSURLConnection GET页面。我想知道是否可以向页面发送js请求(点击HTML无线电输入)然后GET页面。

请求本身GET此页面:enter image description here

我想要做的是在GET页面之前,点击右边的Show All radio inputHTML input是图中突出显示的行。)

所以radio input没有值,正如输入通常那样,它有一个类(ShowAll)。

ShowAll再次出现在网页的来源中,作为js脚本,

$(".ShowAll").click(function () {
            var schk = $(this).is(':checked');
            var sarea = $(this).closest('tr').attr('id');
            // if id starts with tr_, strip off the tr_ to get the area
            if (sarea.substring(0, 3) == 'tr_') {
                sarea = sarea.substring(3);
            };
            if ($("#hStudentID").val() != "-1") {
                // has the data been loaded yet?  If not, load the data now.
                if ($("#b" + sarea + "Loaded").val() == 'True') {
                    AjaxLoad($("#SP_" + sarea), '/novi/StudentPortal/Home/LoadProfileData/' + sarea + '^' + schk);
                    var pos = eval($('#SP_Detail').scrollTop());
                    var ntop = eval($("#tr_" + sarea).offset().top);
                    $('#SP_Detail').animate({
                        scrollTop: (pos + ntop) - 125
                    }, 1000);
                };
            };
        });
        var bisshown = false;
        $(".isshown").each(function () {
            if (this.value == "True") {
                bisshown = true;
            };
        });
        if (bisshown == false) {
            if ($("#hascontent").val() == 0 && $("#haslinks").val() == 0) {
                $("#noarea").show();
            } else {
                $('#SP_Detail').animate({
                    scrollTop: (0)
                }, 1000);
            };
            $("#lnk2print").hide();
        } else {
            $("#noarea").hide();
            $("#lnk2print").show();
        };
        $("#erSubmit").prop("disabled", true);
        $("#erReset").prop("disabled", true);
    });
    function SetMenuHeight(menuHeight) {
        var height = 0;
        var body = window.document.body;
        if (window.innerHeight) {
            height = wi…

那么是否可以发送首先点击此广播输入的request(或其他内容)以及然后 GET该页面?

2 个答案:

答案 0 :(得分:0)

我不确定您要做的是什么,但是如果您向页面发送请求以选择单选按钮(您不能),然后再次调用该页面,您将收到的页面将是最初的图。

从您提供的代码看起来,当选中该复选框时,会执行AJAX请求并相应地更新UI。

如果您需要选择单选按钮来显示相关数据,理想的方法是将页面加载到UIWebView对象中。请求完成后,使用stringByEvaluatingJavaScriptFromString上的UIWebView方法运行您的JavaScript,如下所示:

document.getElementById('_chkassignments').checked = true; 

然后,一旦内置JavaScript执行了AJAX调用,您就可以获取页面的更新内容。

这会回答你的问题吗?

答案 1 :(得分:0)

简短的回答是否定的,您不会在GET请求中调用客户端JavaScript。

这种问题有两种方法:

  1. 就像我们在your other question中所做的那样,启动Charles,在网络浏览器中运行网页并查看正在生成的请求,然后您可以编写{手动生成这些请求的{1}},NSURLConnectionAFNetworking代码。这是与您的Web服务器交互并检索您在Web浏览器中通过JavaScript检索的结果的一种方式。

  2. 如果您确实需要运行JavaScript(如果我了解您的业务问题,在这种情况下您不需要),另一种方法是在NSURLSession中加载页面,然后你可以使用UIWebView在Web视图中调用一些JavaScript。但是,您只能在网络视图中运行JavaScript,而不是通过基本的stringByEvaluatingJavaScriptFromString请求。

  3. 在这种情况下,您正在运行的Javascript基本上是在扩展和折叠当前可见的内容(如果需要,可以通过AJAX检索其他信息,如果还没有)。因此,除非您在Web视图中显示它,否则运行该特定JavaScript是没有意义的。如果您只是想要数据,请确定Web服务器的请求,写下您的请求,然后绕过尝试直接与JavaScript接口的复杂性。