I want to know where is gsmarena.com put ajax url when they do a search. I tried to explore the source of it and I found this function:
function autocompleteLoadList() {
if (AUTOCOMPLETE_LIST !== null) return;
AUTOCOMPLETE_LIST = false;
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest
} else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP")
} catch (x) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP")
} catch (x) {
AUTOCOMPLETE_LIST = null
}
}
}
xhr.open("GET", AUTOCOMPLETE_LIST_URL, true);
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4)
if (xhr.status == 200) {
var data;
if (window.JSON) {
data = JSON.parse(xhr.responseText)
} else {
data = eval("(" + xhr.responseText + ")")
}
AUTOCOMPLETE_MAKERS = data[0];
AUTOCOMPLETE_LIST = data[1];
if (typeof AUTOCOMPLETE_CALLBACK != "undefined") AUTOCOMPLETE_CALLBACK()
} else {
AUTOCOMPLETE_LIST = null
}
};
xhr.send(null)
}
http://cdn2.gsmarena.com/w/js/autocomplete.js?ver=2
I do not know where they put the url to doing a search.
when I open the network tab in Google Chrome console there is also no url to POST or GET. how could they do it?
Related
I have made an webrtc program which is working fine on intranet but not working on internet. I have made the firewall of router to off now don't know what is getting wrong.
Here is my code:
<?php
global $db;
if(isset($_REQUEST['room_id'])){
$room_id=$_REQUEST['room_id'];
require_once 'modules/Conferencingrooms/Conferencingroom.php';
$conferencingroom=new Conferencingroom();
$conferencingroom->retrieve($room_id);
$branch_id=$conferencingroom->branch_id;
}
else{
sugar_die('Error! Access is Denind');
}
?>
<script>
if (window.location.protocol != "https:")
window.location.href = "https:" + window.location.href.substring(window.location.protocol.length);
</script>
<video src="" id="localVideo" style="border:1px red dotted">Patient Video</video>
<video src="" id="remoteVideo" style="border:1px red dotted">Doctor Video</video>
<script>
var pc;
var callNo = '<?php echo $room_id;?>'; // 0 indicates callNo not initialised yet
var caller = <?php if($branch_id==$current_user->branch_id) echo 'true';else echo 'false'?>;
if (caller) {
$("#ajaxStatusDiv").show();
}
var video_constraints={
mandatory:{
maxWidth:320,
maxHeight:320,
maxAspectRatio:16/8,
maxFrameRate:500,
}
}
navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia.bind(navigator);;
navigator.getUserMedia({audio: true, video: true}, onUserMediaSuccess, onUserMediaError);
function onUserMediaSuccess(stream) {
document.getElementById('localVideo').src = webkitURL.createObjectURL(stream);
document.getElementById('localVideo').play();
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
pc = new PeerConnection({iceServers: [ {url:'stun:stun01.sipphone.com'},
{url:'stun:stun.ekiga.net'},
{url:'stun:stun.fwdnet.net'},
{url:'stun:stun.ideasip.com'},
{url:'stun:stun.iptel.org'},
{url:'stun:stun.rixtelecom.se'},
{url:'stun:stun.schlund.de'},
{url:'stun:stun.l.google.com:19302'},
{url:'stun:stun1.l.google.com:19302'},
{url:'stun:stun2.l.google.com:19302'},
{url:'stun:stun3.l.google.com:19302'},
{url:'stun:stun4.l.google.com:19302'},
{url:'stun:stunserver.org'},
{url:'stun:stun.softjoys.com'},
{url:'stun:stun.voiparound.com'},
{url:'stun:stun.voipbuster.com'},
{url:'stun:stun.voipstunt.com'},
{url:'stun:stun.voxgratia.org'},
{url:'stun:stun.xten.com'},
{
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: 'webrtc#live.com'
},
{
url: 'turn:192.158.29.39:3478?transport=udp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
},
{
url: 'turn:192.158.29.39:3478?transport=tcp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
}]});
pc.preventSSLAutoAllowed = false;
pc.autoReDialOnFailure = true;
pc.setDefaultEventsForMediaElement = false;
pc.addStream(stream);
pc.onicecandidate = function (evt) {
console.log('On Ice Candidate');
console.log(evt.candidate);
if (!evt.candidate) {
console.log('inner');
pc.onicecandidate = null;
if (pc.localDescription) postLocalData();
}
};
pc.onaddstream = function(evt) {
document.getElementById('remoteVideo').src = webkitURL.createObjectURL(evt.stream);
document.getElementById('remoteVideo').play();
};
if (caller){
console.log('Create Offer called');
pc.createOffer(onDescCreated, onCreateOfferError);
}
else {
getRemoteData();
}
window.onbeforeunload = function() {
/*
stream.stop();
if (caller && callNo > 0) navigator.sendBeacon('deleteCall.php', callNo);
*/
};
}
function onUserMediaError(err) {
if(err.name=='DevicesNotFoundError'){
alert('Media device is not connected');}
console.log('User media error: ' + err.name);
}
function onCreateOfferError(err) {
logError('Error creating offer: ' + err.name);
}
function onDescCreated(desc) {
pc.setLocalDescription(desc, onLocalDescSuccess, onLocalDescError);
}
function onLocalDescSuccess() {
if(caller)
console.log('offer create success');
if (pc.iceGatheringState == 'complete') {
if(caller)
{
console.log('Send for store sdp for caller');
}
else{
console.log('Send for store sdp for callee');
}
postLocalData();
}
}
function onLocalDescError(err) {
logError("Local description could not be created: " + err.name);
}
function postLocalData() {
console.log('Storing local sdp');
var xhr = new XMLHttpRequest();
var sdp=pc.localDescription.sdp;
xhr.open('POST', 'index.php?module=Conferencingrooms&action=AjaxCalls&storeSdp=true&caller='+caller);
xhr.onload = (caller ? getRemoteData : waitForConnection);
xhr.send(callNo + '~' + sdp);
}
function getRemoteData() {
console.log("Checking db for remote sdp");
var xhr = new XMLHttpRequest();
xhr.open('GET', 'index.php?module=Conferencingrooms&action=AjaxCalls&fetchSdp=true&caller='+caller+'&callNo=' + callNo);
xhr.onload = processRemoteData;
xhr.send();
}
function processRemoteData() {
if (this.response) {
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
var sdp = new SessionDescription();
sdp.type = (caller ? 'answer' : 'offer');
sdp.sdp = this.response;
console.log('Processing remote sdp: ' + sdp);
pc.setRemoteDescription(sdp, onRemoteDescSuccess, onRemoteDescError);
}
else
setTimeout(getRemoteData, 1000);
}
function onRemoteDescSuccess() {
console.log("Remote sdp successfully set");
if (caller) {
waitForConnection();
}
else
pc.createAnswer(onDescCreated, onCreateAnswerError);
}
function onRemoteDescError(err) {
logError("Remote description could not be set: " + err.name);
}
function onCreateAnswerError(err) {
logError("Error creating answer: " + err.name);
}
function waitForConnection() {
console.log('Waiting');
if (pc.iceConnectionState == 'connected' || pc.iceConnectionState == 'completed') {
console.log('Waitingdsadsd');
logError('Connection complete');
caller = null;
document.getElementById('remoteVideo').ondblclick = function() {
this.requestFullscreen = this.mozRequestFullScreen || this.webkitRequestFullscreen;
this.requestFullscreen();
}
}
else
setTimeout(waitForConnection, 1000);
}
function logError(msg) {
console.log(msg);
if (caller && callNo > 0) navigator.sendBeacon('deleteCall.php', callNo);
}
</script>
This is an php signalling version in which room is created on passing room id in the url
I want to validate groupname.
I am using ajax but it is not working
This is my view
<?php echo form_input(['name'=>'groupname','class'=>'form-control','placeholder'=>'Enter group name','value'=>'','ng-model'=>'myWelcome[0].groupname','onkeyup'=>'loadValid(this.value)']) ?>
Javascript function
<script type="text/javascript">
function loadValid(v) {
if(v)
{
var url= window.location.href;
var res = url.split("/");
var groupid = res[res.length-1];
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", site_url + "admin/Usergroup_controller/store_edit_group_name_ajax/" + groupid + "/" + v, true);
xhttp.send();
}
else
{
document.getElementById("demo").innerHTML = "Group name is required field.";
}
}
</script>
Controller function
public function store_edit_group_name_ajax($groupid,$groupname)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('groupname', 'Group name', 'trim|required|alpha|is_unique[group.groupname]|min_length[3]');
if( $this->form_validation->run() )
{
echo form_error('groupname','<p class="text-danger">','</p>');
}
}
Please help...
Make sure you are creating a response object first.
$response = new stdClass();
if ($this->form_validation->run() == false)
{
$response->status = 'failure';
$response->error = validation_errors('<p class="text-danger">', '</p>');
}
...
return $response;
In Javascript after getting response;
document.getElementById("demo").innerHTML = xhttp.responseText.error;
Just echo-ing ajax results is something you need to leave immediately. Please take it as a friendly advise.
I am working on Codeigniter, i am facing one problem i have to show the user error message when he is uploading any other file type to server using ajax. I do not want to load view again to show the error message. My code is as follows:
Please help me to solve my problem.'
View:
function upload_video_Data(a)
{
var fd = new FormData(document.getElementById('posting_comment_'+a));
fd.append("file_m_id",a);
var bar = $('.bar');
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.onreadystatechange=function() {
if (xhr.readyState==4 && xhr.status==200) {
document.getElementById("nameTest").value=xhr.responseText;
}
}
xhr.open("POST", "Dashboard/do_upload_video");
xhr.send(fd);
function uploadProgress(evt) {
if (evt.lengthComputable) {
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
$("#status").animate( { width: percentComplete.toString()+"%"}, 5);
}
}
}
Controller:
public function do_upload_video()
{
$lecture_id=$_POST['file_m_id'];
$output_dir = "./uploads/";
$fileName = $_FILES["save_movie_".$lecture_id]["name"];
if(!move_uploaded_file($_FILES["save_movie_".$lecture_id]["tmp_name"],$output_dir.$fileName))
{
echo '0';
}
else
{
echo '1';
}
}
Use this code before your ajax to validate the extension of file
var ext = $('#my_file_id').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
alert('invalid extension!');
}
Now your code look like this
function upload_video_Data(a)
{
var ext = $('#my_file_id').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
return false;
}
var fd = new FormData(document.getElementById('posting_comment_'+a));
fd.append("file_m_id",a);
var bar = $('.bar');
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.onreadystatechange=function() {
if (xhr.readyState==4 && xhr.status==200) {
document.getElementById("nameTest").value=xhr.responseText;
}
}
xhr.open("POST", "Dashboard/do_upload_video");
xhr.send(fd);
function uploadProgress(evt) {
if (evt.lengthComputable) {
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
$("#status").animate( { width: percentComplete.toString()+"%"}, 5);
}
}
}
Title is pretty explicit to what I'm trying to do. I want to retreive the variable vavlue in the URL and then send it to add.php.
The reason I don't simply put the PHP code in html is because of a FORM which also send var to add.php
PHP Code :
<?php
$id = $_POST["id"];
?>
Javascript in blabla.html?id=test
<script>
function getResults()
{
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("here").innerHTML=xmlhttp.responseText;
}
}
var id = getParameterByName("id");
var data = "id="+document.getElementById("id").value;
xmlhttp.open("POST","add.php",true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(data);
}
</script>
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
var data = "id="+document.getElementById("id").value;
^^^^--string containing the letters 'i' and 'd'
should probably be
var data = "id="+document.getElementById(id).value;
^^-- variable named "id"
try this function
function getParameterByName( name ) {
var parts = window.location.search.substr(1).split("&");
var p_arr = {};
for( var i = 0; i < parts.length; i++ ) {
var temp = parts[i].split("=");
if ( decodeURIComponent( temp[0] ) != "" ) {
p_arr[decodeURIComponent( temp[0] )] = decodeURIComponent( temp[1] );
}
}
return p_arr[name];
}
function getResults() {
var xmlhttp;
if ( typeof XMLHttpRequest !== 'undefined' ) {
xmlhttp = new XMLHttpRequest();
}
else {
var versions = [ "MSXML2.XmlHttp.5.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.2.0", "Microsoft.XmlHttp" ];
for( var i = 0, len = versions.length; i < len; i++ ) {
try {
xmlhttp = new ActiveXObject( versions[i] );
break;
}
catch(e) {}
}
}
xmlhttp.onreadystatechange = function() {
if ( this.readyState === 4 && this.status == 200 ) {
document.getElementById( "here" ).innerHTML = xmlhttp.responseText;
}
};
var id = getParameterByName( "id" );
var data = "id="+document.getElementById( id ).value;
xmlhttp.open( "POST", "add.php", true );
xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
xmlhttp.send( data );
}
I'm calling a PHP file with XMLHttpRequest, but now the call doesn't complete and I
have no idea why. The req.readyState isn't 4, and I don't know why because the PHP file is okay and does exactly what supposed to (just echo a string).
Can anyone see what I can not see?
function processAjax(id, option) {
if (option == "lpath") url = "<?php echo $mosConfig_live_site;?>/administrator/components/com_joomlaquiz/getinfo.php?id=" + id;
else url = "<?php echo $mosConfig_live_site;?>/administrator/components/com_joomlaquiz/getinfo.php?cat=" + id;
//create AJAX request
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv();
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv();
req.open("GET", url, true);
req.send();
}
}
}
//this function handles the response from the ajax request
function targetDiv() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
//all of the code below doesn't happen because its not the option
if (option == "lpath") {
var response = req.responseText.split('##');
var articles = response[0].split(';');
var quizes = response[1].split(';');
document.getElementById("article_id").innerHTML = "";
document.getElementById("quiz_id").innerHTML = "";
for (var i = 0; i < articles.length; i = i + 2) {
if ((i + 1) <= articles.length) {
var option = new Option( /* Label */ articles[i + 1], /* Value */ articles[i]);
document.getElementById("article_id").options.add(option);
}
}
for (var i = 0; i < quizes.length; i = i + 2) {
if ((i + 1) <= quizes.length) {
var option = new Option( /* Label */ quizes[i + 1], /* Value */ quizes[i]);
document.getElementById("quiz_id").options.add(option);
}
}
delete req, articles, quizes;
} else {
document.getElementById("catdiv").innerHTML += req.responseText;
document.getElementById("allchildren").value = req.responseText;
}
} else { //failed to get response
alert("Problem: " + req.statusText);
}
}
document.getElementById("catdiv").innerHTML += "Y U NO COMPLETE?!";
}
req.onreadystatechange = targetDiv();
should be
req.onreadystatechange = targetDiv;
The original code calls targetDiv() immediately after that line of code is run, which is probably not what you wanted to do. The fixed code calls the function correctly, after the Ajax request is received.