Guest User

Untitled

a guest
Oct 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. <div id="wrapper">
  2. <h1>Create Issue</h1>
  3. <form id="create-form">
  4. Summary: <input type="text" name="summary" id="summary" value=""/>
  5. Description: <input type="text" name="description" id="description" value="" />
  6. Issue Type: <input type="text" name="type" id="type" value=""/>
  7. Username: <input type="text" name="user" id="user" value=""/>
  8. Password: <input type="password" name="pass" id="pass" value=""/>
  9. <input type="button" id="button" value="Create Issue"/>
  10. </form>
  11. </div>
  12. <script>
  13. $('#button').click(function() {
  14. $.ajax({
  15. type: "POST",
  16. url: "jiraapi.php",
  17. data: $('#create-form').serialize(),
  18. success: function(data){
  19. alert(data);
  20. },
  21. dataType: "html"
  22. });
  23. });
  24. </script>
  25.  
  26. <?php
  27. $base64_usrpwd = base64_encode($_POST['user'].':'.$_POST['pass']);
  28.  
  29. $ch = curl_init();
  30. curl_setopt($ch, CURLOPT_URL, 'http://localhost:8080/rest/api/2/issue/');
  31. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  32. curl_setopt($ch, CURLOPT_POST, 1);
  33. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
  34. 'Authorization: Basic '.$base64_usrpwd));
  35.  
  36. $arr['project'] = array( 'key' => 'TP');
  37. $arr['summary'] = $_POST['summary'];
  38. $arr['description'] = $_POST['description'];
  39. $arr['issuetype'] = array( 'name' => $_POST['type']);
  40.  
  41. $json_arr['fields'] = $arr;
  42.  
  43. $json_string = json_encode ($json_arr);
  44. curl_setopt($ch, CURLOPT_POSTFIELDS,$json_string);
  45. $result = curl_exec($ch);
  46. curl_close($ch);
  47.  
  48. echo $result;
  49. ?>
Add Comment
Please, Sign In to add comment