Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How can I redirect an ajax request in php/wordpress.
I tried header("Location: " . "http://redirect.url"); but it doesn't work, the response has 301 Moved Permanently status and the request fails.
You cannot redirect from php by an ajax request. Instead of that you need to do it inside your javascript.
For example if this is your ajax then after success of your request redirect from ajax itself
$.ajax({
type : 'post',
url : 'http://localhost/redirect.php',
success : function(data){
window.location = "http://your/url";
}
});
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Hi i wana make a request in my script to a other page and the request have some get Parameters they come back.
(I dont wana do this with ajax only php in one script)
this should be done without redirecting to other page. I wana make this in the background to validate the data they come back from the other page in one script
www.example.de -> request www.exampel2.de/?ex=1
then i will validate the example2 get parameter in example.de
Any solutions?
PHP's cURL functions will allow you to perform advanced HTTP requests. You can use file_get_contents to access REST APIs:
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I want to alert the user that their action is successful when they click the button, here is my code. Please Help. Thanks in advance.
<script type="text/javascript">
function postck3() {
$.post('insert_home.php', {
INSERT_WELCOME: CKEDITOR.instances.CKWELCOME.getData()
});
}
</script>
Try
$.post('insert_home.php',{INSERT_WELCOME:editor_data3}).done(function(data){
alert("Success data return ed from server is "+ data);
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
i got this simple points system, where when a user clicks on the image it adds 20 points to the database through a mysql query. It works, however, I'm trying to make it so that when a user clicks on the image that it not only adds points to a users database but also goes to a website. I added correctly but then it links but doesn't add points. Any help would be appreciated.
Use Ajax for inserting points in your database and after response(in your success method) send it to your desired URL.
$.ajax({
type: "POST",
url: '/test/points.php',
data: formData,
success: function (dataCheck) {
if (dataCheck) {
window.location = 'www.example.com';
}
}
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is it possible to parse an external php file via XMLHttpResquest? If not, how would I exectute an external php file on a page, or load the script into the document?
You would have to make a CURL request from your PHP to a server which is geared to serve raw PHP code rather than execute it. Normally servers don't print the server-side code so you might have some issue there.
You can then use the eval() function to execute raw PHP code
http://php.net/manual/en/function.eval.php
Also, I would recommend finding an alternative to whatever it is you are trying to achieve because, unless you know exactly what you are doing... it sounds wrong.
According to same origin policy you cant . XMLHttpResquest can only call scripts from same server.
But there is a hook for this. I dont know how exactly you do this in core javascript, but in jQuery you can do something like this:
var aURL="SOME_EXTERNAL_URL";
$.ajax({
url: aURL+"&callback=?",
data: "message="+commentdata,
type: 'POST',
success: function (resp) {
alert(resp);
},
error: function(e) {
alert('Error: '+e);
}
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Here's the deal:
I have blog, where I can only use a javascript and free php server. I need to send form data to that php server (this I know how to do), and return some info back to the blog page. Is that even possible?
The only way I can think with out cross domain request is as below
1) make this form in your blog
<form action="FULL_URL_TO_YOUR_PHP_FILE">
/// your fields
</form>
2) in your php file save data received from form and serialize the data(that you want to send back to your blog) in url format like
if you want to pass name and surname YOUR_BLOG_URL?name=myName&surname=MySurname and make redirect from your php file to your blog
header('location:YOUR_BLOG_URL?name=myName&surname=MySurname');exit;
3) now on your blog make an onload event like if you have jquery than
$(document).ready(function(){
alert(window.location.href);
// do some spliting or regexp or anything else to get your data from url
})