0

I have two pages that I am dealing with. My first is a form we will call mainform.php that holds a form that users write down test results from tests they have conducted. These test results are submitted into a database upon submission of the form. Within mainform.php I have a Jira issue slider tab that users can log issues they run into while running the tests. My second page (issueSubmit.php) is the page that interacts with the JIRA Rest API and sends the information the JIRA. The output of the command is a bunch of info including a JIRA issue number.

My question is, what would be the best way to have the JIRA issue number sent back to the first page (so that it can be attached to those test results). Keep in mind that mainform.php is not being refreshed and the user is not navigating away from it until they hit the form submit button. I thought about AJAX but from what I have read I am not sure AJAX by itself is enough. Any suggestions would be great.

4
  • when you come back to the previous page, the mainform.php, wont you have the latest content ? coming back should be a new HTTP request. Commented Aug 26, 2013 at 12:56
  • Read jQuery.post() and jQuery.ajax() Commented Aug 26, 2013 at 12:56
  • Because the user is going the the issueSubmit.php before they have submitted the form on mainform.php, I just have it open a separate window for the issueSubmit.php. The reasoning is that I do not want the data they have entered to be lost if they are sent to a different page before form submission. Commented Aug 26, 2013 at 12:58
  • you want the data in first page to automatically update like comments in facebook posts ? read upon socket.io, what you want is server push also called reverse AJAX. Commented Aug 26, 2013 at 13:22

2 Answers 2

1

Have issueSubmit.php return the data you received from your API call. You can use JSON to do this pretty easily:

$results = $example->myApiCall();
echo json_encode($results);

Then, in mainform.php, your Ajax call could look something like:

$.ajax({ 
        method: "post",
        url: 'issueSubmit.php',
        data: {myVar: customViariable},
        success: function(data){
            var result = JSON.parse(data);
            console.log(result);
            //Check the dev console in your browser
            //Do something with returned data
        } 
});
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, That seems like it is a great solution. I do have a question though. As I am not so familiar with ajax, what is the "data: {myVar: customVariable}" representing?
It is the data you are sending via Ajax. In this case, the POST variable $_POST['myVar'] would be sent to issueSubmit.php and it would have whatever value is in the JavaScript variable customVariable.
0

The page issueSubmit.php can be invoked with ajax itself, while invoking it the JIRA issue number will be returned in turn as a response without refreshing the form. Now the returned response can be used for displaying.

Comments

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.