Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have generated a website:

HTML
http://www.mysite/page.aspx?var1="123"&var2="456"


I am looking to extract var1 and var2 with an Ajax and jQuery program using the GET method.

I am using jQuery:

HTML
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>


I got a part of a Program;

JavaScript
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $.ajaxSetup({
            cache: false,
            dataType: "html",
            error: function(xhr, status, error) {
                alert('An error occurred: ' + error);
            },
            timeout: 30000,
            type: "GET",
            beforeSend: function() {
                console.log('In Ajax beforeSend function');
            },
            complete: function() {
                console.log('In Ajax complete function');
            }
        });
        //I want to extract var1 and var2 into textboxes
    });
</script>


Any help would be appreciated.
Posted

1 solution

No, your var1 and var2 and their values are not part of HTTP request data, they are the part of request URI itself. So, take the current URI window.location and extract the parameters.

[EDIT]

You will find enough code samples doing it, such as:
http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery[^],
http://stackoverflow.com/questions/1280557/extract-parameter-value-from-url-using-regular-expressions[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900