I created self-signed certificate and bind with site for using https protocol and also its working fine in IIS but problem is that whenever I access contained webservice url(https://webservice/webmethod) into jquery ajax call for posting data and its cant work.
enter code here
<script src="jquery-1.9.1.js"></script>
<script type="text/javascript">
function btncallWebService() {
$.ajax({
//url is just for understanding
url: 'https://localhost/.../EditFormServices.asmx/WebSvcSave',
data: { sData:"bbbb" },
method: 'post',
dataType: 'xml',
success: function (respo) {
alert("success"+respo.d);
},
error: function (error) {
alert("error");
}
});
}
</script>
Here we go:
Your url is wrong
<script type="text/javascript">
function btncallWebService() {
$.ajax({
//url is just for understanding
url: '/WebSvcSave',
data: { sData:"bbbb" },
type: 'POST',
dataType: 'xml',
success: function (respo) {
alert("success"+respo.d);
},
error: function (error) {
alert("error");
}
});
}
</script>
Hope it helps;)
Related
I've been testing my site by having friends try it, and some friends get the 403 Forbidden error on any function using ajax. I'm confused why only some of them get the error, especially when everyone used the same browser. Does anyone know why? I'm using Django as a framework and I think I've done everything in the documentation here
Example of one of my functions using ajax:
$('#button').click(function(){
$.ajax({
url: '/get_url/',
type: "POST",
data: {
data_name: data_to_send
},
beforeSend: function (xhr) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
},
success: function (data) {
//change some html text using data
},
error: function (error) {
console.log(error);
}
});
});
use this:
$('#button').click(function(){
$.ajax({
url: '/get_url/',
type: "POST",
data: {
data_name: data_to_send
},
headers: {
"X-CSRFToken": "{{ csrf_token }}",
},
success: function (data) {
//change some html text using data
},
error: function (error) {
console.log(error);
}
});
});
Fixed by making sure all of my form tags had method='post' and {{ crsf_token }}.
When I run the application in IIS, it stucks in Home controller and doesn't continue to the next controller(Data controller) as I wrote in the URL. When I run this in debug mode, it works, not in IIS. How can I fix it?
<script type="text/javascript">
alert('1');
$(document).ready(setInterval(function () {
$.ajax({
url: '/api/data/',
data: { pcName: '' },
type: 'GET',
success: function (CLID) {
//
if (CLID != null) {
$.ajax({
data: { line: CLID },
type: 'POST',
datatype: 'html',
url: '/Home/PopPage/',
success: function (data) {
var w = window.open("about:blank", 'PopPage', 'height=300,width=200');
$(w.document.body).html(data.toString());
}
});
}
}
});
}, 2000));
</script>
Try the razor syntax for creating URL
url : '#Url.Content("~/api/controllername/actionname")'
url : '#Url.Content("~/Home/PopPage")'
OR
url: '#Url.Action("PopPage", "Home")'
because, after hosting, you need to consider the Application name given in the iis. This could be an issue
I have a function which i want to execute when ajax makes a successful request but it doesn't execute here my jquery part
$.ajax({
type: "POST",
url: "https://www.example.com/create_chat.php",
data: dataString,
beforeSend: function()
{
$("#loading_indicator").show();
},
success: function(response)
{
$(".example").html(response);
}
});
here is the response from php file
<script>start_chat(); alert("testing");</script>
i tried adding this also
$(".example").find("script").each(function(i) {
eval($(this).text());
});
but nothing works
Your response from create_chat could indicate which function will be used. For example
$.ajax({
type: "POST",
url: "https://www.example.com/create_chat.php",
data: {
dataString: dataString
},
beforeSend: function()
{
$("#loading_indicator").show();
},
success: function(response) // response could be 1,2,3,4.. etc
{
if(response==1) {
start_chat();
}
if(response==2) {
stop_chat();
}
if(response==3) {
change_chat_room();
}
...
$(".example").html(response);
}
});
While there are work arounds, you should never be executing the response of an Ajax call directly.
"Scripts in the resulting document tree will not be executed,
resources referenced will not be loaded and no associated XSLT will be
applied."
http://www.w3.org/TR/XMLHttpRequest/#document-response-entity-body
Best practice is to respond with data, typically in the form of JSON, JSONP or HTML.
Try This,
$.ajax({
type: "POST",
data: {
'dataString': dataString
},
url: 'https://www.example.com/create_chat.php',
success: function(data) {
start_chat();
alert('Success');
},
error: function(data) {
alert('failed');
}
});
I am having trouble getting an ajax GET request (or any request for that matter) to retrieve the response. I am simply trying to return the response in an alert event:
<script>
$(document).ready(function() {
$('#test').click(function() {
$.ajax ({
type: 'Get',
url: 'https://crm.zoho.com/crm/private/json/Potentials/searchRecords?authtoken=XXX&scope=crmapi&criteria=(((Potential Email:test#email.com))&selectColumns=Potentials(Potential Name)&fromIndex=1&toIndex=1',
dataType: 'json',
success: function(data) {
alert(data);
}
});
});
});
</script>
I can get this and other similar post requests to work by taking away the function in the success option and editing the code like this:
<script>
$(document).ready(function() {
$('#test').click(function() {
$.ajax ({
type: 'Get',
url: 'https://crm.zoho.com/crm/private/json/Potentials/searchRecords?authtoken=XXXX&scope=crmapi&criteria=(((Potential Email:test#email.com))&selectColumns=Potentials(Potential Name)&fromIndex=1&toIndex=1',
dataType: 'json',
success: alert('success')
});
});
});
</script>
Why is this? And more importantly, how can I retrieve the response data and transfer it to an alert message? Any help is appreciated!
** Update:
Upon reading the first two users' responses on this question, this is what I have:
<script>
$(document).ready(function() {
$('#test').click(function() {
$.ajax ({
type: 'GET',
url: 'https://crm.zoho.com/crm/private/json/Potentials/searchRecords?authtoken=418431ea64141079860d96c85ee41916&scope=crmapi&criteria=(((Potential%20Email:test#email.com))&selectColumns=Potentials(Potential%20Name)&fromIndex=1&toIndex=1',
dataType: 'json',
success: function(data) {
alert(JSON.stringify(data));
},
error: function(data) {
alert(JSON.stringify(data));
}
});
});
});
</script>
I am able to get the error response, so I can confirm there is some kind of error. I also want to point out that I am making the request from a different domain (not crm.zoho.com) so should I be using jsonp? If so, how would I alter the code?
When you have
success: alert('success')
you do NOT have a successful request, you are actually executing this function at the start of AJAX method. The success parameter requires a pointer to a function, and when you use alert('success') you are executing a function instead of providing a pointer to it.
First thing that you need to try is to update type to GET instead of Get:
$.ajax ({
type: 'GET',
Try using the .done() function as follows:
<script>
$(document).ready(function() {
$('#test').click(function() {
$.ajax ({
type: 'Get',
url: 'yourUrl',
dataType: 'json',
}
}).done(function(result) {alert(data);}) //try adding:
.error(function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);})
});
});
the error function will also give you some information in your console as to the status of your request.
I'm trying to get my javascript function to use ajax to call a php script. The php script will update a MYSQL table but I've tested the PHP script and it works fine.
This is my function:
function rate()
{
$.ajax({
data: '' ,
url: 'update.php',
method: 'GET',
success: function(msg) {
alert(msg);
}
});
}
and the function is called later with:
rate();
The php script doesn't need any information given to it, it just needs to be called, can anyone point out where I'm going wrong.
Just use like in this example:
<script>
function rate() {
$.get("update.php");
}
</script>
If you dont need to pass the data to the PHP page, you can omit 'Data' from the ajax parameters.
<script>
function rate(){
$.ajax({
url: 'update.php',
method: 'POST',
success: function(msg) {
alert(msg);
}
});
}
rate();
</script>
Have you included jquery library
Try this
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script>
function rate()
{
$.ajax({
data: '' ,
url: 'update.php',
method: 'GET',
success: function(msg) {
alert(msg);
}
});
}
rate();
</script>
Here is an example of how I use the ajax call:
$.ajax({
type: "POST",
url: "page_url",
dataType: 'json',
data: {
'date1' : date1,
'call': 'function_name'
},
beforeSend: function(){
$("#loading").show();
},
success : function(response){
},
complete: function(){
$("#loading").hide();
}
})
and on php part I add:
function function_name($request){
your code here
}
if (!empty($_POST['call'])) {
die($_POST['call']($_POST));
}
i show my all working code, try it:
<html>
<head>
<script type="text/javascript" src="/js/jquery-1.8.2.js"></script>
<script>
function rate() {
$.get("update.php");
}
</script>
</head>
<body>
<button onclick="rate()">Click me</button>
</body>
</html>