我有一个非常基本的问题(我确信)-我有一个Zoho应用程序,我正在使用他们的REST API从表中恢复单个结果。
我想在javascript变量中使用该结果-表单请求如下所示:
<form id="Latest" method="POST" action="https://creator.zoho.com/api/xml/my-company-culture/view/PageFeed_Report">
<input type="hidden" name ="authtoken" value="**********************">
<input type="hidden" name ="scope" id="scope" value="creatorapi">
<input type="submit" value="View Records">
</form> 我可以使用下面的代码自动提交表单
<script type="text/javascript">
document.getElementById("Latest").submit();
</script>这将恢复结果--但我想将此结果赋给一个javascript变量,并在下一段代码中使用它(在相同的框架内)。
我是个新手,所以请温文点!感谢您的帮助。
发布于 2013-11-25 23:27:38
使用jQuery很容易做到这一点:
<form id="Latest">
<input type="hidden" name ="authtoken" value="**********************">
<input type="hidden" name ="scope" id="scope" value="creatorapi">
<input type="submit" value="View Records">
</form>
<div id="result"></div>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$('#Latest').submit(function(event) {
// Stop form from submitting normally
event.preventDefault();
var url = "https://creator.zoho.com/api/xml/my-company-culture/view/PageFeed_Report";
// Get some values from elements on the page:
var $form = $( this );
var authtokenData = $('#authtoken').attr('value');
var scopeData = $('#scope').attr('value');
// Send the data using post
var posting = $.post( url,
{
authtoken: authtokenData,
scope: scopeData
}
);
// Put the results in a div
posting.done(function( data ) {
// empty results div
$("#result").empty()
// write POST result to results div
$("#result").append("<p>" + data + "</p>);
});
});
</script> https://stackoverflow.com/questions/20196247
复制相似问题