Spotify App中的PHP后端无法正常工作

时间:2012-06-29 00:42:20

标签: javascript jquery html spotify

我正在尝试制作一个spotify应用程序,它接收用户信息并将其发送到SQL数据库。但是,我不希望使用ajax完成此操作,因为我希望提交信息以将用户移动到新页面,同时将信息在后台发布到数据库。

到目前为止,这是我的代码:

function complete2() {
var name = document.getElementById("inputname").value;
var form = '<form action="http://site.net/dbconnect.php" method="post" style="display:none">' + '<input type="text" name="name" value="' + name + '">' + '</form>';
$('body').append(form);
$(form).submit();
}

 </script>
 </head>
 <body>
<form id = "submitform" name = "submitform" action = "index.html" method = "POST" onsubmit = "complete2();" >
Name: <input type = "text" id = "inputname"> <br>
<input type = "submit" value = "Create">
</form>
 </body>
 </html> 

2 个答案:

答案 0 :(得分:1)

所以我知道你不想使用AJAX但是如果你想在你的本地应用程序中加载一个不同的html文件并且Spotify不尊重内部资源的位置标题,那么你就是坚持使用ajax。但是,您可以将其与标准帖子的内容类似:

$(function(){
  $('#submitform').submit(function(e){
     e.preventDefault();
     $.post(
         $(this).attr('action'), 
         {'inputname': $(this).find('#inputname').val()}, 
         function(){ window.location.href = 'sp://yourapp/nextpage.html'; }
     );
  });
});

答案 1 :(得分:0)

以下是获取数据的示例

$.getJSON("http://www.exx.com/getjsondata.php", function (data) {
parsetheresponse(data) ; 
} 

以下是发布数据的示例(仍以JSON格式)

$.post("http://www.exx.com/postdataspotify.php", { albumname: "test", username: "test2" });

希望它会有所帮助。

不要忘记将http://www.exx.com放在清单文件中。

相关问题