用于创建Jira问题的PHP表单不起作用

问题描述 投票:0回答:1

我是有关使用php和api的初学者。我正在尝试使用Jira Rest Api创建一个新的Jira问题。这是我的第一个此类项目。我将在我的2页中发布以下代码。我不知道是什么问题。我提到我已经使用高级REST客户端(与POSTMAN基本相同的工具)对api进行了测试,当我在其中进行测试时,它在我的网站上没有运行。我提到在我的代码中,“ JIRA PLACEHOLDER”已替换为实际的jira实例。

Jira-create-issues.php

<?php
    $base64_usrpwd = base64_encode($_POST['user'].':'.$_POST['pass']);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://JIRA-PLACEHOLDER/jira/rest/api/2/issue/');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
                                                'Authorization: Basic '.$base64_usrpwd)); 

    $arr['project'] = array( 'key' => 'TEST');
    $arr['summary'] = $_POST['summary'];
    $arr['description'] = $_POST['description'];
    $arr['issuetype'] = array( 'name' => $_POST['type']);

    $json_arr['fields'] = $arr;

    $json_string = json_encode ($json_arr);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$json_string);
    $result = curl_exec($ch);
    curl_close($ch);

    echo $result;
?>

以及jira-create-issue.html的代码:

<html>
<head>
<script src="jquery-2.1.4.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="wrapper">
    <h1>Create Issue</h1>
    <form id="create-form">
        Summary: <input type="text" name="summary" id="summary" value=""/>
        Description: <input type="text" name="description" id="description" value="" />
        Issue Type: <input type="text" name="type" id="type" value=""/>
        Username: <input type="text" name="user" id="user" value=""/>
        Password: <input type="password" name="pass" id="pass" value=""/>
        <input type="button" id="button" value="Create Issue"/>
    </form>
</div>
<script>
$('#button').click(function() {
     $.ajax({
       type: "POST",
       url: "jira-create-issue.php",
       data: $('#create-form').serialize(),
       success: function(data){
          alert(data);
       },
       dataType: "html"
    });
});
</script>
</body>
</html> 
php html api jira jira-rest-api
1个回答
0
投票

没有提交按钮? (类型=提交)

更改

<input type="button" id="button" value="Create Issue"/>

to

<input type="submit" id="button" value="Create Issue"/>

如果这不起作用,请尝试在控制台中查看JavaScript错误?特别是在POST上。

您还忘记了表单操作。尝试添加;-)

<form id="create-form" action="Jira-create-issues.php"     method="get">
© www.soinside.com 2019 - 2024. All rights reserved.