简体   繁体   English

如何从Ajax响应调用获取目标页面上的数据参数

[英]How to get data param on the destination page from Ajax response call

I am Opening dynamically a page using Ajax, to prevent browser refresh. 我正在使用Ajax动态打开页面,以防止浏览器刷新。 It opens and it runs scripts on the destination page. 它会打开并在目标页面上运行脚本。 but before executing the script, I want them to retrieve the parameters like request.querystring but in Javascript. 但是在执行脚本之前,我希望他们在Javascript中检索诸如request.querystring之类的参数。

This is my code that opens the page. 这是我打开页面的代码。

    function cargarPagina(para1) {
        $.ajax({
            url: "/tarea.aspx",
            context: document.body,
            data: { "p1": para1 },
            type: 'POST',
            success: function (responseText) {

                $("#maincontent").html(responseText);
                $("#maincontent").find("script").each(function (i) {
                    if ($(this).text() != "") {
                        $("#maincontent").find("#hola").val(para1);

                        //alert(para1); //eval($(this).text());
                    }


                });
                },
                async: true
            });
    }

After that, the tarea.aspx opens and executes scripts blah blah. 之后,tarea.aspx打开并执行脚本等等。

But before executing scripts, I want to get the "para1" value that was sent within the ajax POST call. 但是在执行脚本之前,我想获取在ajax POST调用中发送的“ para1”值。

Any help would be much appreciated. 任何帮助将非常感激。

You are doing a POST not to the page, but to a server . 您不对页面进行POST,而是对服务器进行POST。 The server then looks at your POST and says "oh, it looks like this is the page that you are requesting", and serves up some html content. 然后,服务器查看您的POST并说“哦,看起来这是您要请求的页面”,并提供一些html内容。 The javascript on that served up page does not have any knowledge of the original POST, or how it (the page) came to be created. 该投放页面上的javascript不了解原始POST或如何创建(页面)。

If you want to get the POST parameters into the destination page, you must handle the POST request on the server, and then write the parameters in to the output page, via ASP.net or PHP or whatever scripting language you are using. 如果要将POST参数放入目标页面,则必须在服务器上处理POST请求,然后通过ASP.net或PHP或所使用的任何脚本语言将参数写入输出页面。

Alternatively, you could use GET instead of POST, and then the parameters would be available in the URL 或者,您可以使用GET而不是POST,然后该参数将在URL中可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM