Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Ajax jQuery
I have generated a website:
 
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:
 
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
 
I got a part of a Program;
 
<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 21-Feb-13 6:53am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100