read php file rendered html using ajax - javascript

I am just trying to read the file content of a rendering HTML of URL
Here the code i am using , its always going in error section .
$.ajax({
type: 'POST',
url: 'http://www.withholding32.com/api/wh32calc.php?userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0',
dataType: 'html',
success: function(data) {
alert('success');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('error');
}
});
but in case i run the same url directly in browser , its show me html.
here is url

Working DEMO
You can use this in your head tag
<script src="https://rawgithub.com/IonicaBizau/jQuery-cross-domain-requests/master/js/jquery.xdomainajax.js">
</script>
code
$.ajax({
url: 'http://www.withholding32.com/api/wh32calc.php?userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0', // Or your web page link
type: 'GET',
success: function(res) {
var headline = res.responseText;
$('body').append(headline);
}
});
Hope this helps, Thank you

Try the below code:
$('document').ready(function() {
$.getJSON('http://anyorigin.com/get?url=' +
encodeURIComponent('http://www.withholding32.com/api/wh32calc.php?userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0') + '&callback=?',
function(data){
$("#result").html(data.contents);
});
});
Refer : http://jsfiddle.net/R7EPt/275/

Change your request type to GET, all your parameters are given in the URL.

if you are using post method for the ajax than you can't pass argument with url and also add control origin to your php file.
try this...
AJAX code:
$.ajax({
type: 'POST',
url: 'http://www.withholding32.com/api/wh32calc.php',
dataType: 'html',
async:false,
data: 'userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0',
success: function(data) {
alert('success');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('error');
}
});
PHP CODE:
header("Access-Control-Allow-Origin: *");

Related

How to get each data before ajaxSend in JSON not after complete/success

I want all the ajax params before sending an ajax request in JSON format and I need to encrypt each value in JSON and again pass to the ajax request.
I get data in URI format as see in below code, not in JSON. How can I get that?
Around 200 Ajax in this format:
$.ajax({
type: "POST",
url: site_url + "user/user/login_action",
data: login_parms,
success: function (data) {
},
error: function (xhr, textStatus, errorThrown) {
}
});
Before Ajax Call:
$(document).ajaxSend(function(event, jqxhr, settings) {
console.log("settings :",settings.data);
});
Console log:
settings : vEmail=disha.c1%40grr.la&vPassword=123456789
Also if in AJAX use formData then how we can get each value of form data?
If you want to send a AJAX JSON CALL you must to use:
$.ajax({
type: "POST",
url: site_url + "user/user/login_action",
dataType: "json",
async: false,
contentType: "application/json",
data: JSON.stringify(login_parms),
success: function (data) {
},
error: function (xhr, textStatus, errorThrown) {
}
});
if you want to modify the param:
$.ajax({
beforeSend: function(xhr){
this.data
}
});

php sending values to ajax faild error

I Am trying to send value from ajax to php and retrieve it just to test that everything is work, when i click in a button to test i got error and alert('Failed') Appears , how can i fix it in order to get success? thanks
Ajax :
var a = "test";
$.ajax({
url: "search.php",
dataType: "json",
data: a ,
success: function(data) {
alert('Successfully');
},
error: function(data) {
alert('Failed');
}
})
PHP :
<?php
$pictures = "img1";
echo json_encode($pictures);
?>
I refined your code slightly and it works.
var a = "test";
$.ajax({
type: 'POST',
url: 'search.php',
data: 'a=' + a,
dataType: 'json',
cache: false,
success: function (result) {
alert('Successful');
},
error: function (result) {
alert('Failed');
}
});
If you're requesting a JSON, use the $.getJSON from jQuery, it's aready parse the JSON into a JSON object for you.
Seems that you're not return an actual JSON from server, maybe this is what is causing the error.
If you're seeing the 'Failed' message probably the problem is a 500 error which is a server error.
Try this code above.
Javascript:
var a = "test";
$.getJSON("search.php", {
a: a
}, function (json) {
console.log(json);
});
PHP:
<?php
$pictures = ["img1"];
echo json_encode($pictures);
The only way to this not work, is if you have a huge mistake on you webserver configuration.
Your ajax is wrong, it should be:
var a = "test";
$.ajax({
type: "POST",
url: "search.php",
dataType: "json",
data: {a:a},
success: function(data) {
alert('Successfully');
},
error: function(data) {
alert('Failed');
}
});

How to get rid from ?callback=myCallback&_=1340513330866?

I'm trying to capture data from an HTML page that is on the another website. I need to capture that data and save it into my site. That's why I used cross domain ajax like this
var myCallback = function(data) {
console.log(data);
};
var formData = $('.data-capture-form').serialize();
$.ajax({
url: 'http://prospectbank.co.uk/leads/capt',
type: 'GET',
data: formData,
dataType: 'jsonp',
crossDomain: true,
jsonp: 'callback',
jsonpCallback: 'myCallback'
}).done(function(res) {
console.log(res);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
});
Then I get this error
Any help? Thanks
The response from http://prospectbank.co.uk/leads/capt?_=1340513330866? is wrong formatted JSON.
{"status":true}
It should be
{status:true}

Ajax not working in url with parameters

I have a problem with ajax. The code works correctly on this url http://www.web.com/index.php?s=formulario but not in this http://www.web.com/index.php?s=formulario&var=1050
In the urls with parameters ajax returns no results but other works perfect.
I can't find the problem. Any help?
Mi code is:
$(document).ready(function(){
var consulta;
$("#dni").focus();
$("#dni").keyup(function(e){
consulta = $("#dni").val();
$("#resultado_dni").delay(1000).queue(function(n) {
$("#resultado_dni").html('<img src="ajax-loader.gif" />');
$.ajax({
type: "POST",
url: "comprobar_dni.php",
data: "b="+consulta,
dataType: "html",
error: function(){
alert("error peticiĆ³n ajax");
},
success: function(data){
$("#resultado_dni").html(data);
$("#valid_dni").val(data);
n();
}
});
});
});
});
Try to change 'dataType' to:
dataType: "json",
After ajax is complete, callback data should be parsed by type.

JQuery ajax function does work but php script is not working

alright so here is my problem i have got a jquery function and a php script
jquery function:
function set_session(para){
//Send Ajax request
var dataString = 'waarde='+ para ;
jQuery.ajax({
url: '../js/set_session_side.php',
type: 'POST',
data: dataString,
cache: false,
success: function(data, textStatus, xhr) {
console.log(data); // do with data e.g success message
},
error: function(xhr, textStatus, errorThrown) {
console.log(textStatus.reponseText);
}
});}
set_session.php:
<?php
$_SESSION['side'] = $_POST['waarde'];
?>
when i run the jquery function there is a succes, but no data, and my php script is not working/ or not being triggerd, because $_SESSION['side'] is not changing.
any help would be appriciated.
thanks in advance
First make sure your requesting script is correct.
add sesstion_start() at the beginning of your set_session.php
( i believe your problem is here);

Categories

Resources