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

时间:2022-10-18 07:27:29

I am Opening dynamically a page using Ajax, to prevent browser refresh. 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.

我使用Ajax动态打开页面,以防止浏览器刷新。它会打开,并在目标页面上运行脚本。但在执行脚本之前,我希望他们在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.

任何帮助将非常感激。

1 个解决方案

#1


0  

You are doing a POST not to the page, but to a server. 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. 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.

您正在执行POST而不是页面,而是服务器。然后,服务器查看您的POST并说“哦,看起来这是您要求的页面”,并提供一些HTML内容。该服务页面上的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中提供参数

#1


0  

You are doing a POST not to the page, but to a server. 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. 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.

您正在执行POST而不是页面,而是服务器。然后,服务器查看您的POST并说“哦,看起来这是您要求的页面”,并提供一些HTML内容。该服务页面上的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中提供参数