0
我想發送一個位圖和一些字符串字段到服務器,我已經徹底檢查沒有參數是空的。這是我的Ajax代碼ajax發送空值到servlet
var URL = "ProfileUpdater";
var username = $("#cp-setup-username").val();
var email = $("#cp-setup-email").val();
var birthday = $("#cp-setup-birthday").val();
var aboutYou = $("#cp-setup-about-you").val();
var intrests = $("#cp-setup-intrests").val();
var phoneNumber = $("#cp-setup-phone-number").val();
var sessionid = $.cookie('WhitePages_SessionID');
var session_username = $.cookie('WhitePages_Username');
var legal = emptyCheck(username,email,birthday,aboutYou,intrests,phoneNumber);
alert(username +" " + email + " " + birthday +" " + aboutYou + " " +intrests + " " + phoneNumber +" "+ sessionid +" " + session_username);
alert(result);
if(legal){
alert(sessionid + " " + session_username) ;
alert("about call server");
$.ajax({
type:'POST',
url : URL,
processData:'false',
contentType:'false',
data:{Username:username,Email:email,Birthday:birthday,AboutYou:aboutYou,Intrests:intrests,PhoneNumber:phoneNumber,sessionid:sessionid,username:session_username,Image:result,FieldsChanged:fieldsChanged,isMultiPart:isMultiPart},
success:function(data){
alert("success");
alert(data);
}
});
}
,這是我的servlet代碼:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ProfileUpdater extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String user = request.getParameter("Username");
String sessionid = request.getParameter("sessionid");
String username = request.getParameter("username");
//sessionid and username is null
PrintWriter out = response.getWriter();
out.println(sessionid +" " + username + " " + user);
System.out.println("hello " + username + "your session id is " +sessionid + " " + user);
}
}
我已經把警報在我的劇本,他們是不是空的,但在響應它爲空。我的意思是我認爲它發送空服務器。有人可以告訴我我要去哪裏嗎?謝謝。
檢查瀏覽器啓動工具是否發送了請求參數? –