/ AJAX कॉल कम्प्लीट के बाद / कोड नहीं चल रहा है - जावास्क्रिप्ट, jquery, ajax

AJAX कॉल पूर्ण होने के बाद कोड नहीं चल रहा है - जावास्क्रिप्ट, jquery, ajax

पहला ईवेंट श्रोता ठीक काम करता है। जब दूसरा ईवेंट श्रोता चलता है, तो मैं फायरबग और रिटर्न में POST देख सकता हूं, लेकिन alert("test") कभी नहीं होता।

$(".walkthrough").click(function(){
var url = $(this).data("story");
var num = $(this).data("revert");
$("#tableauViz").replaceWith("<div id="tableauViz"></div>")
$.post("",{method: "getTicket", url: url},function(data){
switchToStory(url,data);
$("#help").html("<p>You are currently viewing the walkthrough, click here to <a href="#" data-num=""+num+"" class="exitWalkthrough">go back</a>.</p>");
});
});
$("#addViz").click(function(){
var url = $("#Viz-URL").val();
var name = $("#Viz-Name").val();
var expression = /[-a-zA-Z0-9@:%_+.~#?&//=]{2,256}.[a-z]{2,4}b(/[-a-zA-Z0-9@:%_+.~#?&//=]*)?/gi;
var regex = new RegExp(expression);
if(url.match(regex) && name != ""){
url = url.replace("http://","").replace("https://","");
console.log(url);
$.post("",{
user_key:"5",
method: "addViz",
url:url,
name:name
},function(data){
alert("test");
},"json");
} else {
alert("Please enter a valid URL and Name");
}
});

क्या किसी को वहाँ कुछ भी दिखाई देता है जो इसे रोक रहा है? मैं इस समस्या को कैसे दूर कर सकता हूं?

उत्तर:

जवाब के लिए 0 № 1

जब अजाक्स अनुरोध करते हैं, तो यह हमेशा एक अच्छा होता हैएक त्रुटि कॉलबैक प्रदान करने के लिए विचार करें, भले ही आपको लगता है कि इसे कभी भी नहीं बुलाया जाएगा। एक के बिना, आपके पास कोई समस्या का निदान करने का कोई तरीका नहीं है जो isn "t नेटवर्क से संबंधित है।

सभी jQuery के अजाक्स तरीके (.load के अलावा) एक jQuery वादा वस्तु को वापस करते हैं, जो किया, असफल और हमेशा तरीके। किसी भी विफलताओं को पकड़ने के लिए असफल विधि का उपयोग करें।

$.post(url, data, successHandler).fail(function (xhr, status, reason) {
console.log(
xhr, // this is an object, it will contain the response text, headers, etc
status, // the http status of the response, 20x or 30x for success
reason // this is the reason that the response failed
);
});

आपके मामले में, यह विफल हो गया क्योंकि खाली स्ट्रिंग वैध जसन नहीं है।


उत्तर के लिए -2 № 2

आपको अपने .post से पहले खाली arg "" को हटाने की जरूरत है, किसी खाली जगह के साथ url ओवरराइट हो जाएगा।

$.post({
user_key:"5",
method: "addViz",
url:url,
name:name
},function(data){
alert("test");
},"json");