I am wanting to use AJAX to create a screen area that overlays on the current window. An example of one of these is like those adverts that don't open in a new window or when you are on reddit and try and vote on a post without being logged in. I can't find any documentation on such a thing. Does anyone know how to do this?
I'm not very much clear what you are asking.But What I undestood is , you want an overlay when ajax request is sent.
So, the solution for that is below .
In Html :
With Jquery :
$.ajax({
url: "#Url.Action("GetMyCandidate")",
contentType: "application/json; charset=utf-8",
dataType: "json",// your type
beforeSend: function () {
// show your overlay div
$("#overlay").show();
}
}).success(function (data) {
$("#overlay").hide();
// your futher code
});
Related
Right now i'm using jsp and bootstrap to make my front-end, and i have an option to make a new register inside a modal and this new register needs to be in my behind screen, in the past projects I used angular and it was very easy to do, but now using jsp I haven't any ideia to make it without submit my modal.
Is there a way to make it without submit my modal?
You can use Ajax, that way you can post the form to back-end to make what you need to do and than return the object to front-end.
Seeing your tags you're be able to make like that
Controller:
#Post
public void methodName(final T entity) {
.
.
.
result.use(Results.json()).withoutRoot().from(insertedObject).serialize();
}
Front:
$.ajax({
type : 'POST',
url : 'method url',
data : form.serialize(),
success : function(data){
// data is the object inserted
}
});
I have one scenario i.e., need to compare the values from Website with Database(MS Sql Table Values)
In my website having one datatable which is dynamic and the values changed based on Username.
I need to check whether the values present in datatable(website) should match with the Database.
Kindly let me know any ideas and code snippet for this.
You can use Javascript/Jquery that when a user change a value in datatable send a Ajax asyncron request to the java server and here check the values.
For example:
$( ".target" ).change(function() {
$.ajax({
type: 'POST',
url: 'myUrl',
data: JSON.stringify(myValues),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
})
});
Possibly I would load the data from MySQL -> Put it in Some POJO that mimics my datatable -> And preValidate the data -> put it in datatable.
Please put out some code which you have tried already.
Is there a way to send ajax requests in a Java program? I was thinking that there might be a jquery library somewhere, but I don't even know if jquery would be something that I should use. I'm trying to get the data from a certain request from a website as shown in this function:
function searchFraze(fraze, page) {
page = typeof page !== 'undefined' ? page : 1;
$.ajax({
url: 'ajax/tradeCsRight.php',
type: 'POST',
data: "search=1&type=10&fraze="+fraze+"&page="+page,
success: function(data) {
$("#itemlist").html(data);
}
});
}
Basically, I want to POST custom data in the data field above to the website (http://csgolounge.com/). Honestly, I don't even know if I should be doing what I'm doing this way, or if I should use some other method.
Also, in FireBug, I can see the contents of the tradeCsRight.php file as seen here (which is my goal, to see the html content of this): http://i.imgur.com/8ACnGbp.png
If I open the actual file in chrome, however, the page and html is blank (http://i.imgur.com/LHtKyUb.png). Can someone tell me why this is?
I have a web applicaton with java jsp servlet.
On the right side of my web frontend i have a list with links on the right side. (This is my sidebarright.jsp)
If i push the minus picture a pop window will be open (The popup window is also a jsp page named deletelink.jsp).
In the popup page i have a list of a links, and i can choose with checkboxes which links i want to delete.
So if i delete a link, in the database its allright, but i have to update with F5 the startside. Only then i will see that i have delete a link.
So i want to update with Ajax and Jquery the linklist(sidebarright.jsp), without refreshing the whole start side.
My ajax and jquery part in my deletelink.jsp page to delete links is this:
$(document).ready(function(){
$('#setdeletefilelink').submit(function(){
var id=5;
$.ajax({
url: '<%=request.getContextPath()%>/issues?action=uploaddeletelink&wherestatement='+id,
type: 'POST',
dataType:'json',
data: $('#setdeletefilelink').serialize(),
success: function(data){
alert ("success in ajax");
alert(data);
//sideBarRight.location.reload();
//alert("hallo");
//If you want to return anything in jsp.
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
alert("failure");
$("#result").html('there is error while submit');
}
});
// close();
});
});
My response from the servlet is this
if (lstrAction.equalsIgnoreCase("uploaddeletelink")){
String wherestatement;
try{
LinkUploadService linkUploadService= new LinkUploadService();
linkUploadService.deleteLink(wherestatement);
//Sende anfrage wieder zurück zur JSP
response.setCharacterEncoding("text/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().println("Hallo ich bin ein Servlet");
response.getWriter().write(new Gson().toJson("TEST"));
}
else{
wherestatement = "";
}
}catch(Exception e){
}
this.checkAndDoBackgroundAction(request);
}
After the action in the servlet a don't get the repsone in my success section in the ajax script part. I don't know why ?
and the otherthing is: how i can say to refresh the right side bar jsp.
You said the popup is a diffrent file. Is it opend in a iframe then?
The success function isn't called, because the form gets submitted, maybe this would help there:
$('#setdeletefilelink').submit(function(e){
e.preventDefault();
a form without a action, is submitting to its self, maybe if you try this:
$('#setdeletefilelink').submit(function(e){
//...Ajax call here
e.preventDefault();
return false;
});
otherwise, you have to check in firebug, if there is an error or an ajax reqeust anyways..
As the right side, is on the same page, it should go like this, when you get the success to work:
success: function(data){
//an identifire for the right side would be nice
$("#ID_ofTheRightSide", parent.document).html(data); //depending on what you getting back...
}
I'm parsing a webpage with Jsoup which so far is going good, except that when I parse, I get the data that's the 'default text', the text displayed right before a javascript changes the value.
There's
<span id="p1name" class="redtext">Player 1</span>
which I can parse with
Element player1Div = doc.getElementById("p1name");
p1name = player1Div.text();
player1.setText(p1name);
Then there's a script on the website
<script>
$(document).ready(function() {
getData();
});
function getData() {
$.ajax({
type: 'get',
url: '../data.json',
data: '',
dataType: "json",
success: function(data) {
player1name = data['p1name'];
$("#p1name").text(player1name);
</script>
which changes the element's text. So I thought I could just run the java code again and get the new text, but that won't work as I keep getting "Player 1" (whereas I'm sure it should display a different string)
What are my options? How do I solve this?
JSoup can't solve your problem. All Jsoup knows is parse and extract the data.
As the desired text is not part of the html during the parsing it can't be extracted from the Document
All you can do is, issue a new request to ../data.json and fetch the data. Provided, you know that url before fetching the content.