Nodejs jquery reload div part of page ejs - javascript

I am trying to reload only part of a html page using jquery after a ajax call and everything I've tried gets me 404 not found. Does the jquery.load not work with node js and if so what is a workaround to get one div to reload without reloading the whole page?
$.ajax({
url: "http://localhost:3000/high",
type: "GET",
datatype: "jsonp",
success: function(data){
console.log(data);
var highbtn = JSON.parse(data);
console.log(highbtn);
$('#high').load('/Public/userphotoview.ejs' + ' #high');
},
error: function(){
console.log("error fetching data");
}

Related

JQuery stop large XML parse from crashing page

I'm getting XML data via jQuery, but the XML I am using has 5,000+ pieces of data I want to get. When my page tries to get the data after a few seconds my page freezes and shows "This page is being slowed down" and then crashes.
Is there a way I can get the data without the page crashing? Maybe slow the process down so it doesn't handle so many processes at once? Here is the code I'm using to get the XML data:
$(document).ready(function() {
$.ajax({
type: "GET",
url: "mymxl.xml",
dataType: "xml",
success: function(xml) {
$(xml).find("programme").each(function() {
$("xmlcontent").append($(this).find("title").text());
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
});

Ajax post issue with smarty

I have script using smarty engine.
I just tried to use ajax post to get some data from page.
The javascript function as following:
function getTime(val,id) {
$.ajax({
type: "POST",
url: '{$GLOBALS.site_url}/check_time/',
data:'GetDate='+val + '&Jobid='+id,
success: function(data){
alert(data);
}
});
}
the alert show me (3 small squares) I don't know what dose mean !

Process website content then load it back?

I want to load source code from a url, process its content and then load the url (with the processed info) to the user. How can that be done? (Is it possible using Javascript?)
Thank you in advance!
You need ajax. Using jQuery:
$.ajax({
type: "GET",
url: "your url",
success: function(data) {
alert("OK");
},
error: function(error) {
alert("error");
})

How can I determine the final link of url shortned link without loading within the page?

I have links of messages coming in, say in an email message body. The issue right now is I want to click on the content and be able to display the unwrapped link in the right message pane (I use jQuery).
I am using jQuery and figured that using AJAX to call another PHP script to send the requests to bit.ly, etc. would work. I am not 100% sure how to do this.
The main issue is that some of these links are 2-3 times shortened as Twitter has their own automatic shortner. Any help on this would be appreciated.
Thanks.
You could use a service called LongURL. The API call in jQuery would look something like this:
$.ajax({
url: 'http://api.longurl.org/v2/expand?format=json&url=http%3A%2F%2Fbit.ly%2Fv20RLs',
dataType: 'jsonp',
method: 'get',
success: function(response) {
alert(response['long-url']);
}
});
or
$.ajax({
url: 'http://api.longurl.org/v2/expand',
data: {
format: 'json',
url: 'http://bit.ly/v20RLs'
},
dataType: 'jsonp',
method: 'get',
success: function(response) {
alert(response['long-url']);
}
});

AJAX page fetch ignores javascript on page

I am calling an ajax script to fetch a content of a page and then replace the current contents with the fetched one. One problem I am facing is that there is a javascript on the fetched page which doesnt get rendered and is treated as text. How do I make sure that the javascript gets loaded?
write javascript(fetched page) code in main page.
for example:
$.ajax({
url: "your fetched page url",
dataType: "html",
type: 'POST',
data: "your data",
success: function(data){
$("#result").html(data); //call back div
//put your javascript code from fetched page here
}
});

Categories