How can i call Jquery AJAX external URl in asp.net?
Can jquery ajax code call a webservice from another domain name or another website? Below is the code i amm using,
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
url: "https://developers.google.com/public/oauth2/1/files",
headers: {
'Authorization': headerDATA,
'Content-Type': 'application/json'
},
success: function (data) {
alert("Success");
for (var i = 0; i < data.items.length; i++) {
alert(AJAX);
}
},
error: function (e) {
alert("Failure");
alert(JSON.stringify(e));
}
});
How to solve this one?
1 answer
-
answered 2018-04-17 05:57
Aneesh R S
Sure it can
Your problem is due to the absence of double quotes in the url. url field in the ajax should be string value. Try the code below
$.ajax({ type: "GET", contentType: "application/json; charset=utf-8", dataType: "jsonp", url: "https://developers.google.com/public/oauth2/1/files", headers: { 'Authorization': headerDATA, 'Content-Type': 'application/json' }, success: function (data) { alert("Success"); for (var i = 0; i < data.items.length; i++) { alert(data.items[i]); } }, error: function (e) { alert("Failure"); alert(JSON.stringify(e)); } });
See also questions close to this topic
-
Webpack config to resolve index in folder
I have project, where I uses webpack, react, sass. My project structure and webpack.config below. In project I need for purpose to import write
@import 'styles/BigComp/index.sass'
orimport BigComp from './components/BigComp/Index.jsx'
, but I wanted to omit "index", to set webpack config in way, that it can figure out, that if in folder has fileindex.sass
orIndex.jsx
, then webpack need to import it. In conclusion, I want to writeimport BigComp from './components/BigComp'
to import./components/BigComp/Index.jsx
and write@import 'styles/BigComp'
to importstyles/BigComp/index.sass
. I hope, I make myself clear.// Do not try to run. It's not a code. +components |-+BigComp |-Index.jsx |-ElemOfBigComp0.jsx |-ElemOfBigComp1.jsx |-ElemOfBigComp2.jsx +styles |-+BigComp |-index.sass |-elem0.sass |-elem1.sass
// webpack.config.js const path = require('path'); const rules = [ { test: /\.s[ac]ss$/, use: [ 'css-loader', 'sass-loader', ], }, { test: /\.jsx?$/, use: ['babel-loader'], exclude: ['/node_modules'], }, ]; module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, resolve: { extensions: ['.js', '.jsx'], }, module: { rules }, };
-
I cannot seem to get a seperate ID for each block
I am working on a school project, and I want to add and take fields away (they should clone each other but with different IDs. This is done in javascript. Maybe i'm missing out on something or straight up doing something wrong?
$(document).ready(function(){ var addOpdracht = $('<a/>', { 'class': 'btn btn-primary' }).on('click', function(){ $('.jumbotron').append(getExerciseBlock(i)); }).html('<i class="fa fa-plus"></i>'); $('.jumbotron').append(addOpdracht); for(var i = 0; i< 0; i++){ $('.jumbotron').append(getExerciseBlock(i)); } }) function getAddBtn(target, i){ var addBtn = $('<a/>', { 'class': 'btn btn-primary' }).on('click', function(){ $(target).append(getWordPartInput(i)); }).html('<i class="fa fa-plus"></i>'); console.log(target); return addBtn; } function getExerciseBlock(i){ var eBlock = $('<div/>',{ 'id': i, 'class': 'col-md-12' }); $(eBlock).append(getAudioBtn(i), getWordInput(i), getWordPartInput(i),getAddBtn(eBlock, i)); return eBlock; } function getAddBtn(target, i){ var addBtn = $('<a/>', { 'class': 'btn btn-primary' }).on('click', function(){ $(target).append(getWordPartInput(i)); }).html('<i class="fa fa-plus"></i>'); console.log(target); return addBtn; } function getAudioBtn(id, cValue){ cValue = cValue || ''; var audioBtn = $('<a/>', { 'class': 'btn btn-primary' }).html('<i class="fa fa-volume-up"></i>'); return audioBtn; } function getWordInput(id, cValue){ cValue = cValue || ''; var wInput = $('<input/>', { 'class': 'form-group form-control', 'type': 'text', 'name': 'question_takeAudio_exerciseWord[]', 'placeholder': 'Exercises' }) return wInput; } function getWordPartInput(id, cValue){ cValue = cValue || ''; var wpInput = $('<input/>', { 'class': 'form-group form-control', 'type': 'text', 'value': cValue, 'placeholder': 'Syllables' }); return wpInput; }
So, what the idea should be: I click on var addOpdracht and it adds a whole extra field (it's basically cloning), but I need the clone to get an ID. The first field starts with ID 0, but when I click to clone it gives the second field an ID of 0 aswell. I want it to get ID = 1 so I can send it to a JSON file and later on pull it back based off its ID. so what is it that i'm either doing wrong or not seeing? please clarify this for me aswell.
EDIT: everytime I click on the + sign it basically has to clone but with +1 ID count.
-
The proper use of PHP_EOL
I am trying to write a function in which a string of text is written with timestamps to the file "text2.txt", I want each entry to be on a new line, but PHP_EOL does not seem to work for me.The strings simply write on the same line and does not write to a new line for each string.
Could anyone give me some pointers or ideas as to how to force the script to write to a new line every time the function is activated? Some sort of example would be highly appreciated.
Thank you in advance.
<?php if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['sendmsg'])) { writemsg(); } function writemsg() { $txt = $_POST['tbox'] ; $file = 'text2.txt'; $str = date("Y/m/d H:i:s",time()) . ":" . $txt ; file_put_contents($file, $str . PHP_EOL , FILE_APPEND ); header("Refresh:0"); } ?>
Also, I want to get rid of the character count on the end of the string when using the below code :
<?php echo readfile("text2.txt"); ?>
Is there any way for the character count to be disabled or another way to read the text file so it does not show the character count?
-
issues in my ajax or jquery in codeginter
brother i insert image edit update is working fine but my problem is that when i click edit and delete some image that is the ajax call but its give some error i dont known why this show this error any brother help form me advance thanks
this is my edit code <span style="cursor:pointer;" onclick="javascript:deleteimage(<?php echo $data['id'] ?>)">X</span> </td> </tr> <?php }endif; ?> <tr> <td>Images</td> <td><input type="file" name="userfile[]" id="image_file" accept=".png,.jpg,.jpeg,.gif" multiple></td> </tr> <tr> <td colspan="2" align="center"><input style="width: 50%;" type="submit" value="Submit"></td> </tr> </table> </form> </div> <script> $(document).ready(function(){ function deleteimage(image_id) { var answer = confirm ("Are you sure you want to delete from this post?"); if (answer) { $.ajax({ type: "POST", url: "<?php echo site_url('welcome/deleteimage');?>", data: "image_id="+image_id, success: function (response) { if (response == 1) { $(".imagelocation"+image_id).remove(".imagelocation"+image_id); }; } }); } } }); </script> End show my error is > Uncaught ReferenceError: deleteimage is not defined > at HTMLSpanElement.onclick (VM1166 5:35)
-
How to do the same in AJAX jQuery
I want to search the table data by using an input text field which is on top of the table and its working simply using jquery only but if let's say I have 2000records then it will take time to load. So I want to make a code for same in AJAX where data when user search then only it will search from DATABASE then show us as a result.
$(document).ready(function(){ $("#hidetable").hide(); $("#myInput").on("keyup", function() { var value = $(this).val().toLowerCase(); $("#hidetable").show(); $("#myTable tr").filter(function() { $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1) }); }); $("#myInput").on("keydown", function() { var valuecheck = $(this).val(); if (valuecheck.trim().length > 0) { $("#hidetable").hide(); } }); }); </script> <style> table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%; } tr:nth-child(even) { background-color: #dddddd; } </style> </head> <body> <h2>Filterable Table</h2> <p>Type something in the input field to search the table for first names, last names or emails:</p> <input id="myInput" type="text" placeholder="Search.."> <br><br> <table id="hidetable"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody id="myTable"> <tr> <td>John</td> <td>Doe</td> <td>john@example.com</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>mary@mail.com</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>july@greatstuff.com</td> </tr> <tr> <td>Anja</td> <td>Ravendale</td> <td>a_r@test.com</td> </tr> </tbody> </table> <p>Note that we start the search in a body, to prevent filtering the table headers.</p> </body> </html>
-
javascript check if element rect hitting another with same class
I want to put like 30 of
<img class="anger">
elements with random size and random position inside the<div>
container, but none of the.anger
hitting one another.Is it possible?
This is my code so far:
function loadAngers() { var wrp = '#angerContainer'; //the container var rectAvatar = $('#picAvatar')[0].getBoundingClientRect(); //rect of user avatar var rectWrapper = $(wrp)[0].getBoundingClientRect(); //rect of container listCoorditaes = [[ (rectAvatar.left+rectAvatar.right)/2, (rectAvatar.top+rectAvatar.bottom)/2 ]]; $(wrp).find('.anger').remove(); for (var i=0; i<listAnger.length; i++) { var verb = listAnger[i].replace('assets/img/verb/','').replace('.png','').replace('-',' '); var anger = $('<img src="'+listAnger[i]+'" class="anger hvr-'+getRandom(listAnim)+'" data-verb="'+verb+'" style="position:absolute">'); var paddingX = 100; var paddingY = 200; var wideX = rectWrapper.width - paddingX; var wideY = rectWrapper.height - paddingY - rectAvatar.top; var width = Math.round(30 + Math.random() * 70); var left; var top; var x; var y; var tubrukan = false; var tubrukan_offsetX = 50; var tubrukan_offsetY = 50; var coba = 0; do { //find the best coordinate coba++; x = Math.round(Math.random() * wideX) + paddingX/2; y = Math.round(Math.random() * wideY) + paddingY/2 + rectAvatar.top; left = x - width/2; top = y - width/2; for (var j=0; j<=i; j++) { var cekX = listCoorditaes[j][0]; var cekY = listCoorditaes[j][1]; var difX = Math.abs( x - cekX ); var difY = Math.abs( y - cekY ); if (difX < tubrukan_offsetX && difY < tubrukan_offsetY) { tubrukan = true; break; } } } while(tubrukan && coba<3); //as I give up for eternal loop, I limit the loop with 3 tries. listCoorditaes.push([x,y]); anger.css('width',width+'px'); anger.css('left',left); anger.css('top',top); anger.appendTo(wrp); } console.log(listCoorditaes); }
This is the current result:
The elements still overlap with each other because I limit the loop. If I remove the limit, browser will endure endless loop and become not responding.
Do you have another better way to achieve it?
-
How to make bootstrap input calendar totally visible false in code behind
I have some situation like:
All i want to do is to remove the x icon also the calendar icon.
My HTML
<div class="input-group date form_date col-md-5" id="divDate" runat="server" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd"> <input class="form-control" size="16" id="textBoxInspectionDate" runat="server" type="text" value="" readonly style="min-width:200px"/> <span class="input-group-addon" id="spanClear" runat="server"><span class="glyphicon glyphicon-remove"></span></span> <span class="input-group-addon" id="spanIcon" runat="server"><span class="glyphicon glyphicon-calendar" ></span></span> </div>
Here's my Code:
spanClear.Visible = false; spanIcon.Visible = false;
This code is working but it returns to a page look like:
My problem is: How could i turned the calendar to
visible false
at all in code behind?Or
Is it possible to remove a class which is
input-group date
in a div?Thanks in advance.
-
Highlighting search text with Danish letters in gridview
I have a gridview displaying items from a database. I highlights the string from textbox matching the text in the gridview like this.
if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Text = Regex.Replace(e.Row.Cells[0].Text, txtSøg.Text.Trim(), delegate (Match match) { return string.Format("<span style = 'background-color:#b56612'>{0}</span>", match.Value); }, RegexOptions.IgnoreCase); }
It works, but not with Danish letters (æøåÆØÅ). Then it dosent highlight anything. How do i make that work?
Thanks in advance.
-
how to split and change the font style of a crystal report element?
we are having a report generated using crystal report While generating we have a request to have a checkbox with a list of items. The checkbox is only available in the Wingdings font. Since we are using Arial font for the list items we can not change the font of the formula field through which we are showing the list. Eg: [] task1 [x] task2
we need to split each list item and replace the square brackets with checkbox form the wingdings font.
how can we create a formula for this in crystal report?
-
Reload configuration data without server restart
I have a requirement to reload a configuration file dynamically without restarting the server.
Details with example:
- I have a restful web service deployed in stackato server.
- I am using Jenkins pipeline to build and deploy in the server.
- I need to maintain a configurable data say TTL = 60 anywhere which can be configured, and upon configuring the deployed WAR will reload the data without restarting the server. The data will be dynamically reloaded.
This is very important for me and I need help desperately. Will keep updating this post based on the comments,suggestion and questions.
Thanks
-
Synchroteam Api integration in PHP Wordpress form
enter image description here[i have this form in Wordpress Site and i need to integrate it with Synchroteam Api and send its fields to Synchroteam. I asked Client for the APIs and he send me this Email.
Client: "We have open APIs available . Please visit https://api.synchroteam.com/
Also to access your account through the APIs they would need the authentication key.
Please go into configuration => More => (LHS Down) Authentication Key." ]2
https://api.synchroteam.com/ i have checked this link here is so many APIs i dont know which to use. Please Help.
-
host a website in httpd
I'm using Amazon Linux and I install MySQL, PHP and httpd
/etc/httpd/conf.d here I create new file vhost.conf and add these details
<VirtualHost *:80> ServerAdmin prakash@cleato.com ServerName www.au-m.com ServerAlias www.au-m.com DocumentRoot /var/www/html/domore_aumweb/ ErrorLog /var/www/html/www.au-m.com/logs/error.log CustomLog /var/www/html/www.au-m.com/logs/access.log combined </VirtualHost>
then I restart httpd using
sudo service httpd restart
httpd restart success but when I type my IP in the browser. 1.Its not loading home page of httpd
2.ip/domore_aumweb 404
how can I fix this issue? thank you