here is the webservice url which gets results how to hit that url which gives a result true or false
function uniqueness(){
var xhr;
//var contextpath=document.getElementById("contextpath").value.trim();
var pub_name=document.getElementById('p_name').value.toLowerCase().trim();
var pub_trimed_name=(pub_name).replace(".", "").replace(" ", "").replace("&", "")
.replace("(", "").replace(")", "").replace("-", "");
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xhr=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
var url="http://125.63.88.114:8086/xchangeWebservice/resources/publisher/check_publisher/"+pub_trimed_name;
// alert(url);
xhr.open( 'POST',url, true );
xhr.send(null);
//xhr.add("Content-Type", "application/json");
xhr.onreadystatechange = function (response) {
if (xhr.readyState==4 && xhr.status==200)
{
var det = eval( "(" + xmlhttp.responseText + ")");
var size= det.size();
if (det[0].book_title != "" ) {
alert("invalid ");
}
}
};
}
here is the webservice url which gets results how to hit that url which gives a result true or false
Related
Follownig is my javascript code, ajax function is used to read response from
server. but xmlhttp.status is always 0 in firefox browser, why? please help me.
function ajaxAsyncRequest() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveObject("Microsoft.XMLHTTP");
}
//creating asynchrounous GET request
var tempValUrl = $(".urlVal").val();
var urls = tempValUrl + '/Department/departmentAdminTokenReceive';
xmlhttp.open("GET", urls, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
alert("readyState"+xmlhttp.readyState);
alert("status"+xmlhttp.status);
if (xmlhttp.status == 200) {
var data = xmlhttp.responseText;
//for signing
var signarr = data.split("$$");
//for signing
document.getElementById('signName').value = signarr[1];
document.getElementById('signCertName').value = signarr[2];
document.getElementById('signCa').value = signarr[3];
document.getElementById('signExpiryDate').value = signarr[4];
document.getElementById('signPublicKey').value = signarr[5];
}
}
}
}
Trying to bring over data from PHP. I'm using the urls to display images and then I'm using the tags to reorder the array I'm trying to create called data. I'm not sure if I'm parsing correctly.
var data = [];
function importJson(str) {
if (str == "") {
document.getElementById("content").innerHTML = "";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
data = JSON.parse(xmlhttp.response);
alert(xmlhttp.response);
alert(data);
for (var sport_index = 0; sport_index < data.sport.length; sport_index++) {
var url1 = data.sport[sport_index][1];
alert(data.sport);
}
alert(url1);
}
}
xmlhttp.open("GET", "http://server/~name/folder/many.php");
xmlhttp.responseType = "json";
xmlhttp.send();
function buildImage(imagesrc) {
var img = document.createElement('img');
img.src = imagesrc;
document.getElementById('content').appendChild(img);
}
}
xmlhttp.response looks like this
{"sport":[{"ImagesId":"34","ImagesPath":"http:\/\/server\/~name\/folder\/images\/24-08-2014-1408868419.png","Tag":"sport"},{"ImagesId":"30","ImagesPath":"http:\/\/server\/~name\/folder\/images\/23-08-2014-1408824125.png","Tag":"sport"}],"clothes":[{"ImagesId":"33","ImagesPath":"http:\/\/server\/~name\/folder\/images\/23-08-2014-1408824179.png","Tag":"clothes"},{"ImagesId":"32","ImagesPath":"http:\/\/server\/~name\/folder\/images\/23-08-2014-1408824166.png","Tag":"clothes"}],"food":[{"ImagesId":"31","ImagesPath":"http:\/\/server\/~name\/folder\/images\/23-08-2014-1408824158.png","Tag":"food"}]}
But data looks like [object Object] and when I try to use the urls to create images the elements are undefined.
In a Javascript object, you access elements by name, for instance:
data.sport[sport_index]["ImagesPath"]
Or
data.sport[sport_index].ImagesPath
The function below gets results in ie but not on the other browsers. Any suggestion?
function show_packet(str, company) {
var cam = document.getElementById("company");
if (window.XMLHttpRequest) {
var xmlhttp = new XMLHttpRequest();
} else {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("packet_1").innerHTML = xmlhttp.responseText;
document.getElementById("icon_1").innerHTML = "";
}
}
xmlhttp.open("GET", "show_packet.php?car_moto=" + encodeURIComponent(str, true) + "&cam=" + encodeURIComponent(cam.value, true));
xmlhttp.send();
}
vars and functions are hoisted to the top of their containing function. Declare your var once at the top, and only assign it in the if/else.
Do anyone know what I'm doing wrong or why AJAX callbacks are TOO slow? Here's code:
function new_xmlhttp() {
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function ajax_get(data, args) {
xmlhttp = new_xmlhttp();
xmlhttp.open("GET", "functions.php?" + data, true);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
// OK.
alert(args);
}
}
xmlhttp.send(null);
}
Sometimes it takes 2-3 seconds to load (data is max 10 bytes long.)
Tested on Firefox and Chrome under Linux.
i have sorted xml file on the basis of item no.now i am trying to display data in javascript, but my code doesn't work, can anybody tell me what is wrong here
item.php:
$xmlFile = "items.xml";
$doc= DOMDocument::load($xmlFile);
$item = $doc->getElementsByTagName("item");
$items=array();
foreach($item as $node)
{
$itemno = $node->getElementsByTagName("itemno");
$itemno = $itemno->item(0)->nodeValue;
$quantity = $node->getElementsByTagName("quantity");
$quantity = $quantity->item(0)->nodeValue;
$available = $node->getElementsByTagName("available");
$available = $available->item(0)->nodeValue;
$items[$itemno]= array($itemno,$quantity,$available);
}
ksort($items, SORT_NUMERIC);
foreach($item AS $ite => $no)
{
$itemnum=$no[0];
$qty=$no[1];
$avail=$no[2];
echo $itemnum;
echo $qty;
echo $avail;
}
js:
var xhr = createRequest();
function getit( ) {
xhr.open("GET", 'item.php', true);
xhr.onreadystatechange = getConfirm;
xhr.send(null);
}
function getConfirm()
{
if ((xhr.readyState == 4) &&(xhr.status == 200))
{
var data = xhr.responseText;
alert(data);
}
}
try xmlrequest in this flow in your javascript:
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("tbRow").innerHTML=xmlhttp.responseText;
//lo();
}
}
xmlhttp.open("GET","tbrow.php",true);
xmlhttp.send();
Here "tbRow" is a "div" id. i.e.,
<div id="tbRow"></div>