retreiveing website content after scripts injection - javascript

I'm trying to get a website content but when I use ajax...
$.ajax({
url: url,
type:'GET',
async: false,
success: (data) => websiteContent = data
});
I get only something like <div class="root"></div>. Is there a way to retreive a full webpage code after running all scripts?

Related

Ajax call url in an external js file

I have a web page (written in php / codeigniter) that uses some javascript code.
I tried to move some javascript code to external file to better manage the code.
So in document ready event I load external file with
$.getScript('<?php echo base_url();?>assets/js/offerta_editScontirow.js');
one piece of code, putted in an external js file, does not work; instead it works correctly if I put all the code inside the main php file.
$.ajax({
dataType: 'json',
url: '<?php echo site_url("Offerta/applica_sconti");?>',
cache: false,
data: data,
success: function (data, status, xhr)
{
........
It does not work because it does not elaborate the php code, and in the query string I find
"php echo site_url("Offerta/applica_sconti");?>:"
So, is there a way to have it works? May I pass any parameter to the external js file while loading it, and pass the url to be used in ajax call? Some other method?
Kind regards,
Matt
try this window.my_url = 'some value'; and get the variable like below
window.my_url = '<?php echo site_url("Offerta/applica_sconti");?>';
$.getScript('<?php echo base_url();?>assets/js/offerta_editScontirow.js');
and
$.ajax({
dataType: 'json',
url: my_url,
cache: false,
data: data,
success: function (data, status, xhr)
{

Create an HTTP request, give it a header and open url in a new tab

I need to create in either Javascript or jQuery an http request. In it I need to put some header fields and then send this all to an external url that is on the same server. The target web page needs to read these headers. In short, I need to make a sort of redirect, but which contains header parameters provided. I am trying to do it in the flowing way but it does not redirect:
var mdata = {roles: roles};
$.ajax({
url: "SendRequest",
type: "POST",
data: mdata,
//crossDomain: true,
dataType: "json"
})
.done(function (data) {
$.ajax({
url: "/OimPortalEmulation",
type: "POST",
beforeSend: function(xhr){xhr.setRequestHeader('name', 'Salvo'); xhr.setRequestHeader('groups', data)}
}).done(function(){})
.fail(function(){alert('Redirect Failed!')});
})
.fail(function (data) {
alert("ajax error! ");
})
.always(function () {
});
This works in as much as it calls the target servlet which prints out successfully the header provided, but it does no open a new tab nor does it show the pag in the current tab. How can I resolve this?
FYI: I am using Java Servlets on the server side.
Edit: I provided further details on the problem posted.

Loading data asynchronous with javascript does NOT work?

I want to transfer data via JSON and receive it in a browser via ajax. The data size is about 2 mb and the problem is that firefox does not respond during receivement of the data.
So I want to receive the data in the background, without interrupting the webinterface, but it does not seem to work.
My javascript code
$.ajax({
url: 'http://127.0.0.1:10085/data/getd',
dataType: 'json',
global: false,
success: function (response) {
// just for testing
alert("HI");
},
async: true,
});
Maybe you can help me?
Regards
Marko

Ajax request inside ajax request with Laravel

I have a code that works like this:
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
processData: false,
contentType: false,
dataType: 'html',
This loads:
Route::post('/local/pdf', 'LocalController#subirPDF');
Which loads the controller:
return View::make(Config::get('rv.paginasPDF'));
Which loads:
$.get("{{Request::root()}}/local/actualizar_paginas/9/2");
Which loads the route:
Route::get('/local/actualizar_paginas/{id}/{paginas}', 'LocalController#actualizarPaginas')->where('id', '[0-9]+')->where('paginas', '[0-9]+');
That loads:
Auth::user()->perfil='penadaaaaaafe';
Auth::user()->save();
Don't worry if you see that I don't use some variables, because I have simplified the code to make it easier to explain.
Basically, if I load directly the route from the url everything works fine:
{{Request::root()}}/local/actualizar_paginas/9/2"
But if I load it with the ajax method that I have devoloped it doesn't work. If I console.log the data I recieve the right html code of the $.get page, but It doesn't make the get request.
Any idea how to fix it?
Thanks.

how to transfer the control during success: of jquery to html form

I'm using following jquery statements to validate the user details.
$.ajax({
type: "POST",
url: "Login",
data:'uname='+encodeURIComponent(uname)+'&'+'pass='+encodeURIComponent(pass),
dataType: "json",
//if received a response from the server
success: function( data, textStatus, jqXHR) {
if(data==true)
{
$("#error").show(1500).css({visibility: "visible"});
$("#error").append("<b>success!</b>");
}
but i nee to transfer the control to other html page during success.
$("#error").show(1500).css({visibility: "visible"});
$("#error").append("<b>success!</b>");
I'm trying to change the above statements to transfer the control. Please anyone help me to solve this.
within your successful login condition use:
window.location ='index1.html';
/* or whatever url you want and make sure path is correct relative to page or use absolute url */
This tells browser to open that url using javascript

Categories

Resources