首先,讓我們說我有這段代碼:如何從響應中獲取網址?
// Put the results in a div
posting.done(function(data) {
var content = $(data).find("#content");
$("#result").empty().append(content);
});
什麼從POST請求的對象數據的回報?我想從該帖子請求中獲得響應網址,是否有可能?
這是我的代碼:
<form id="myForm" name="login" action="http://Xsite.com/login" method="post">
<input type="text" id="TID" name="TID" />
<input type="password" id="TClave" name="TClave" />
<input type="submit" value="Login" />
</form>
<script>
$(".myForm").submit(function(event) {
event.preventDefault();
var $form = $(this),
e = $form.find('input[name="TID"]').val(),
p = $form.find('input[name="TClave"]').val(),
url = $form.attr('action');
var posting = $.post(url, { TID: e,TClave: p });
posting.done(function(data) {
// how to get the url for testing here?
alert('data'); // what does this return?
});
});
</script>
什麼'url'你在說什麼?你應該告訴我們你要回來什麼。你很可能返回一個json對象。首先,'alert(data)'會給你這個對象,而'alert('data')'。 – karthikr
它可以返回任何東西,取決於'http:// Xsite.com/login'服務器端代碼處理您的發佈數據的URL。 – Phoenix
我無法訪問服務器端代碼,是否可以從響應中獲取url?服務器端代碼是一個執行登錄驗證的servlet,當憑據無效時,它會返回一個url,如:http://Xsite.com/index?Error=-2,我可以測試響應是否返回該url ? –