I need a web sites some data which I want to parse via jquery. I am able to do everything except the pagination which contain javascript anchor link.
(source: grinshare.com)
2
I want to load the second page (certain selector, say "p #listo") in a paragraph in the 1st page via ajax. Can I do this via ajax? if it is possible, please can you share the code..
Thanks in advance..
Note:
I want to get the 2nd page via ajax...I tried a lot things....
$.ajax({
url: __doPostBack('grdResults$ctl29$ctl01',''),
success: function(data){
//Some function I will perform
}
});
But it reload the page...if I use quotation for url it give error... I tried get, load, post but unable to do it...
You need to have a URL that outputs data and handles pagination on the server side. For example, it could be /mydata/page/3/, and it would grab page 3 of the data and return it in some format (JSON, XML, YAML, whatever).
Then, you can have jQuery send an ajax request on click of each of the items in the pagination controller instead of running __doPostBack().
Switching to ASP.NET MVC would help you.
Related
I'd like to download the data from a URL (which is just a text file), and then be able to use the data in JavaScript, ideally adding each line of the text file to an element of an array.
I've looked around for a simple way to do this but can't seem find anything appropriate.
You're looking for AJAX! It's a API which allows you to submit a request in JavaScript. An easy library to help you get started is jQuery.
Say you want to fetch the contents of example.com/file.txt and display it in an alert:
$.ajax({
url: "https://example.com/file.txt",
}).done(function(r) {
alert(r);
});
AJAX is great because the request is asynchronous, meaning it doesn't have to slow down the loading of the rest of your page: it runs alongside your other code.
Further documentation on jQuery AJAX.
In the database I have something like Line, Word and Character. That is, a Word must belong to a specific Line, the same goes for Character (or you can think of a multi-level menu, each menu item can be another menu). I'm writing a management page to interact with the database. Each time the user insert/delete a record, the page must be refreshed to show the changes. However, this approach is too annoying for my users (although the refresh is automatic). Is it possible to show the changes without refreshing the whole page? If it is, how? Thank you.
UPDATE: The data is shown as multi-level list (the picture below is an example) and can be collapsed/expanded. When I refresh the page, they are all collapsed (which annoys my users).
You can do it using AJAX(Asynchronous JavaScript And XML). You can update a web page without reloading it using ajax. You can use jQuery ajax() which is so simple to integrate. http://api.jquery.com/jquery.ajax/
Here is an example-
$.ajax({
method: "get",
url: "/action.php",
data: {item_id: item_id, vote: vote},
dataType: "html"
})
.done(function(msg){
// Update view of the web page, it could be deleting or updating a div
})
.fail(function(msg){
alert(msg);
});
/*
method - get/post
url - which will handle your request
data - data you want to send to server
dataType - response type, html/json/text etc
*/
If it works without any problem then the done method will trigger otherwise fail method will trigger.
If you are saying something like a live suggestions display while you type on the search bar. The ajax. If you just want to show the newly updated record on the be view page, a redirect would do
Using only javascript only how do I hit a url eg www.google.com and get the google logo display on my page.
I tried this using jQuery, but i want in pure javascript.
$.ajax({
url: 'http://www.somesite.com/',
type: 'GET',
success: function(res) {
$(res).find('div.content').each(function(){
$('#here').append($(this).html());
});
}
});
You're almost there. After you get the data from the server (How to make an AJAX call without jQuery?) you need to parse it and get that page's DOM. Once you have that it's as simple as getting the element that contains the image you want, grabbing the src attribute, and then getting that file. Of course this all depends on the page's structure and form -- a badly made page might be difficult to deal with. Your best bet is to go to the site and either grab the image to store on your system or the link to it.
Here's a question that can help you with parsing the html string into a DOM object: Converting HTML string into DOM elements?
I have a question about what backend to use. I have a html page that has various dropdown lists. On Submit I want to sent the results of that page to another page to compile the (average) results. Is there a way to do this without setting up a database? I was thinking of sending the data with Ajax and then compiling the data with Javascript on the receiving page.
I've done something like this before so any suggestions would be appreciated.
You can use jquery to check the changes in the dropdown list. Send the results to a jquery ajax page and get the return value as json. The result json can be shown on the same page with jquery.
I assume the page you are talking about is an html or jsp page. Yes you can use javascript ot process the data and then send it to a servlet and get it back to another jsp.
I am using jQuery to create a JSON array, and now from the client side how do I pass or post the JSON array to the server/backend from the modal window?
When i click "Save Changes" on the modal window i want to pass/ post the
var data = $(this).serializeObject() to the server.
How can I go about doing it from the client side using jQuery or javascript?
My code is here in jsfiddle http://jsfiddle.net/dev1212/GP2Y6/30/ ( modal window is not showing up in the fiddle when the user click submit but work on my local machine)
Is the right way to go about posting it to the server?
Would this be the right way to pass the JSON array data to the server?
This is my updated version:
$.ajax({
type: 'POST',
url: 'http://re-directb-acktohomepage.com/',
contentType:'application/json'
data: data,
success:
alert('success');
});
Use "$.ajax" and put your json data through the "data" parameter. You will get the data in the request object sending to the server.
Cheers
Look into ajax or handling the httprequest yourself. ajax is really easy since you're using jQuery already.
http://api.jquery.com/jQuery.ajax/
You can either use a form and submit it through javascript like this or you can use AJAX through jQuery like this.
One will redirect your page and one will post the data while keeping your browser on the same page. This question has been answered many times on this site so you could also look around for a more in depth answer.