Trying to automate scanning for flash embed links on other domains - javascript

I tried this code to pull website but when I test it, the alert box doesn't run.
<script type="text/javascript" >
$(document).ready(function(){
$.get( "https://crossorigin.me/https://google.com", function( data ) {
alert( "Data Loaded: " + data );
});
});
</script>

Taken from the documentation, try implementing the .fail method to see what went wrong.
var jqxhr = $.get( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
// Perform other work here ...
// Set another completion function for the request above
jqxhr.always(function() {
alert( "second finished" );
});
Also the author of crossorigin.com warns that
PLEASE DO NOT USE THE PROXY ON A PRODUCTION SITE.
I cannot guarantee the stability of the service, and you will probably experience service interruptions.

Related

Javascript : invalid character error

In my .cshtml page I have JavaScript function it is working fine but showing error like Invalid Character. Here is my code snap :
Please help me. Not getting where is the error.
Please use like this:
.
Please click here for details documentation on Jquery.com
var jqxhr = $.post( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});

jQuery to read json data

I am trying to get jquery to read json data but getting undefined.
$.post( wce_data.url, { userid : userId, token : accessToken }, 'json')
.done(function( data ) {
console.log("data.status: " + data.status);
if (data.status === "success") {
alert("Coupon added");
} else {
alert("failed");
}
})
.fail(function() {
alert("The requested action failed. Please contact the site administrator!");
});
data.status: returns 'undefined'
data: returns {"status":"success"}
Try error checking like this:
.done(function() {
alert( "Coupon added" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
Oh I see. I got it. It was the PHP Output Header that was needed.
I added:
header("Content-type: application/json");
To the PHP for jQuery.
Hope this helped someone new to json like me.

How to call an exception with post method (AJAX)?

If the post method is unsuccessful I want to throw an exception and write to an error log? Basically if this method returns no results I want to throw an exception and write to file.
Post method:
$.post("ip.php", function( data ){
$("#ip").val(data.ip);
$("#country").val(data.country);
$('#campaignID').val(data.campaignID);
}, "json");
Just add the fail(); method.
var jqxhr = $.post( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
For the part of the question:
If the post method is unsuccessful I want to throw an exception (...)
You could chain a .fail() callback method to the $.post() request as mentioned by #Grimbode
Or use $.ajax() instead, where is an error option - function to be called if the request fails.
The $.ajax() equivalent to your $.post() method would be:
$.ajax({
type : "POST",
url : "ip.php",
dataType : 'json',
success : function(data){
$("#ip").val(data.ip);
$("#country").val(data.country);
$('#campaignID').val(data.campaignID);
},
error : function(jqXHR/*object*/, textStatus/*string*/, errorThrown/*object*/){
// throw an error ...
// console.log('Type of error: ' + textStatus);
},
});
As for that part:
(...) write to an error log
It's not possible to write any file with javascript. Since it's a client side scripting language that executes in a client browser, it has no access to the server. Well, that's how it works.

Jquery ajax fail when calling rest webservice

I have a set of REST URIs that i can access after authenticating on the server. This service takes a JSON input with the login information and retrieve a JSON output with the session ID.
When using a Rest client, like a chrome extension, everything works.
Now I want to implement it using JS but despite of the failure return, I can not see any details of what is wrong (error messages are blank) and neither could found what I am missing in my code.
$.ajax({
// the URL for the request
url: "https://host002:50000/b1s/v1/Login",
// the data to send (will be converted to a query string)
data: {
UserName: "manager",
Password: "1234",
CompanyDB: "CUS_001"
},
// whether this is a POST or GET request
type: "POST",
// the type of data we expect back
dataType : "json",
// code to run if the request succeeds;
// the response is passed to the function
success: function( json ) {
$( "<h1/>" ).text( json.title ).appendTo( "body" );
$( "<div class=\"content\"/>").html( json.html ).appendTo( "body" );
},
// code to run if the request fails; the raw request and
// status codes are passed to the function
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem! " + xhr.responseText);
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
},
// code to run regardless of success or failure
complete: function( xhr, status ) {
alert( "The request is complete!" );
}
});
xhr.responseText is always blank. Status is always error. errorThrown is always blank as well.
I tried also the $post method but got the same behavior.
Your JSON is incorrect. Try using this
data: JSON.stringify({UserName: "manager", Password: "1234", CompanyDB: "CUS_001"});
While navigating from one url to other there is a cross-domain error thing which pops up.
Try doing this.
Call to a function on your same url using ajax and from there use CURL request to your web service url.

jQuery $.post success function never fires

I have a $.post which using Fiddler I can see always posts successfully but my success function is never fired.
A successful post to the url returns a 1 or failure returns a 0, on each occasion I have tested it returns the expected value of 1 so I'm at a lost as to what I'm doing wrong?
if ($('#mycheckbox').prop('checked')) {
$.post('/base/MailingList/Subscribe/',
{
listId: $('#mycheckbox').val(),
name: $('#subscriber-name').val(),
email: $("#subscriber-email").val()
},
function(response) {
console.log(response);
});
}
Stick another function as a final callback. That function will run in the failure case.
The way jquery recommends doing it is this:
var jqxhr = $.post( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
I'm not sure if this will help or not, but I always use fully qualified urls when I do any asynchronous calls. You may want to try:
$.post('http://mydomain.com/base/MailingList/Suscribe/', ...
Additionally, you will likely want your handling function to recieve all three argument from the callback (data, textStatus, jqXHR). This way, you can look at the txtStatus to verify if you have success or not.
In my case the problem was header with wrong MIME type ("application/json" instead of "text") in php file on server. If you send header that doesn't match type of data cause an error and $.post calls fail function.

Categories

Resources