我尝试将表单值解析为正文请求的数据变量,但正文总是返回空。这意味着我的脚本无法将用户的字段值类型打印到正文数据中。在HTML表单中:
<form id="my-form">
<input type="text" id="MSISDN" name="MSISDN" placeholder="MSISDN"/>
<input type="text" id="channel" name="channel" placeholder="channel"/>
<button type="submit">Submit</button>
</form>
下面是我的javascript
<script>
$.ajax({
url: 'https://apiurl.com/users',
dataType: 'text',
type: 'post',
headers: {
'accept': 'application/json;charset=UTF8',
'content-type': 'application/json',
'api-key': 'judmkd895849438'
},
contentType: 'application/json',
data: JSON.stringify( { "MSISDN": $('#MSISDN').val(), "channel": $('0').val() } ),
//data: JSON.stringify( {MSISDN: document.getElementById("MSISDN").value, channel: "0"} ),
processData: false,
success: function( data, textStatus, jQxhr ){
$('#response pre').html( JSON.stringify( data ) );
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
}
});
</script>
<div id="response">
<pre></pre>
</div>
如果请求成功,则响应为:
{
"UserDetails": [
{
"status": "Enabled",
"UserID": "ABCS884784",
"UserNo": "897363762827"
}
],
"customerStatus": null,
"responseCode": 0,
"responseMessage": "Details Fetched Successfully "
}
但是在我的代码中,响应总是返回错误
"{\"customerStatus\":null,\"responseCode\":-2,\"responseMessage\":\"Inputs are invalid.\"}"
这意味着主体值没有填满,我不知道到目前为止我的代码出了什么问题
任何帮助都将不胜感激,
https://stackoverflow.com/questions/55129925
复制相似问题