0

I can simply send the data using window.location.href, first store the value to send from testing.html in script tag, variable say

<script> var data = value_to_send window.loaction.href="next.htm?data="+data </script>

this is sending through a get request is there any way to send this through post means without showing in the url ? and please tell the way how can i access that value in another page. Thanks

3
  • why dont you use $.post(); method? Commented Aug 27, 2014 at 18:43
  • can u explain the use of $.post() by taking this example. Commented Aug 27, 2014 at 18:47
  • 1
    $.post("next.htm", {"data" : data}, function(response){ /*do something with reponse eg: alert(response);*/ }); Commented Aug 27, 2014 at 18:48

1 Answer 1

1

As you tagged jquery, Here is a way of making an AJAX call with jquery:

    $.ajax({
        url: "next.htm",
        type: "POST", // This could be POST, GET, PATCH, HEAD, etc..
        dataType: 'json',
        data: JSON.stringify({"value1": "test"}),
        complete: function(data) {
            alert(data);
        }
    });

The complete function, as http://api.jquery.com/jquery.ajax/ says:

A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.

This function is being executed whether the HTTP request is successful or not, so maybe you could handle the different HTTP status in the response, using:

if (data.status == 200) console.log('Request succeed');
Sign up to request clarification or add additional context in comments.

4 Comments

what is this "complete" i had never use this, can u explain it
@lucky just edited the post with quite an explanation and also quoting the jquery doc.
i 'll be accessing that data in next.htm directly as an array with key value1 and its value test, or in any other way
You will receive the data in application/json type so you must be sure that you are receiving it that way, then you will have a var value1 with value test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.