Reputation: 3209
I'm not sure how to best explain this so bear with me.
I have the following in some javascript (using jQuery)
$(document).ready(function(){
$("#myForm").submit(function(){
var request = $.ajax({
url: "myPage.php", //sits on localhost
crossDomain: true,
type: "POST",
data: {
var1 : "foo",
var2 : "bar"
}
});
request.done(function(res){
alert("DONE");
});
request.fail(function(jqXHR , textStatus){
alert(textStatus);
});
}
MyPage.php uses SoapClient to call a service. And then return some data.
I can directly call MyPage.php from the webBrowser and get a result (failed because there is no POST data).
If I try to make the MyPage.php call from the AJAX and put a breakpoint in my service, I see the service being called and returning a value.
But the request.Fail ALWAYS calls. It appears that it just directly jumps to that fail before the service can even finish.
How would I remedy this?
Upvotes: 0
Views: 164
Reputation: 3209
I do not know why, but apparently changing it from $("#myForm").submit(function(){
And moving it into function SubmitForm(){...}
and then making the call from
Fixed the whole thing. Thanks for the advice....
Upvotes: 0
Reputation: 91792
Your syntax is wrong, it should be:
data: {
var1: "foo",
var2: "bar"
}
Upvotes: 1
Reputation: 7905
I may be wrong but aren't you missing the colon between data and the data map? and then you should be doing key : value
not key = value
inside the map.
Upvotes: 1